Solved

How to fix this code

Posted on 2001-06-12
5
184 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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

856 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