Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to fix this code

Posted on 2001-06-12
5
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

618 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