Solved

How to fix this code

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now