Solved

How to fix this code

Posted on 2001-06-12
5
185 Views
Last Modified: 2010-03-05
I have the following code:
$record{'Date'}="992364126";

I call a sub routine:
require "translate_date_time.pl";
($shmonths,$r_in->{'date_order'}) = translate_date_time(); # Read date/time

This subroutine look something like this:
-------------------------------------------------------
@shmonths = qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec);
$date="mon,22-01-69";

return (\@shmonths,$date);
-------------------------------------------------------

My main script looks then:

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($record{'Date'});

print "$shmonths[$mon]";

For example when the $mon = 11, the $shmonths[$mon] has to be "Dec". But tht isn't.
What am I doing wrong??
0
Comment
Question by:netje
  • 3
5 Comments
 
LVL 8

Expert Comment

by:shlomoy
ID: 6184646
arrays start with index 0 and not 1...
0
 

Author Comment

by:netje
ID: 6184727
Sorry what do you mean.
I know that arrays start with 0.
Therefor $shmonths[11] has to "Dec" and not "Nov".
But that is not the problem!!
I get nothing as a result??
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6184791
That's ok.

11 is Nov (the 11th month)
12 is Dec.

$mon is a number from 1 to 12.

That's ok.

0
 
LVL 5

Accepted Solution

by:
marecs earned 50 total points
ID: 6184857
$shmonths is a reference to an array. @shmonths does not exist, therefore $shmonths[$mon] refers to element $mon in @shmonths which does not exist. What you want is

print "$shmonths->[$mon]";
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6184971
$$shmonths[$mon]
should work as well.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl script help 12 107
perl script 4 115
Awk Question 2 132
XML::LibXML and Xpath syntax How do I get attribute of sibling 2 162
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question