Hello there Monks,

For some reason when I pass timelocal() the number 8 for months which is August and the day is 31, it gives me this error.

Day '31' out of range 1..30 at ./myFile.pl line 147

I can post all the code if necessary but I've checked all the variables and it's definitely getting the correct values.


Below is a snippet from my code that is having the issue.

For the code below the 2D array has this data in it. Each element is separated by whitespace

OWNER /ud/QC-DATA/CONTROL 001!SCHEDULE X 3462970 9223372195768565774 userMike 5005444 156 pts/220 11:00:44 Aug 31
WAITING /ud/QC-DATA/CONTROL 001!SCHEDULE X 3462970 9223372195768565774 UserJoe 3309650 35 none 11:03:44 Aug 31

my %months = ('Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12 ); calcTime(); sub calcTime { # These will hold the 'timelocal' for the current OWNER and curren +t WAITER being processed. my $ownTime; my $waitTime; # Loop through all the records and calculate time diff between an +'OWNER' and any 'WAITING' users up until the next 'OWNER'. for (my $x = 0; $x <= $#records; $x++) { #If the current line at the first elemnt is equal to 'OWNER' t +hen... if ($AoA[$x][0] eq 'OWNER') { for (my $y = $x+1; $y <= $#records; $y++) { if ($AoA[$x][0] ne $AoA[$y][0] && $AoA[$x][2] eq $AoA[ +$y][2] && !(exists $AoA[$y][13])) { #Splits field containg the 'TIME' into 3 seperate +variables (hours, minutes, seconds) my ($ohour, $omin, $osec) = split ':', $AoA[$x][10 +]; my ($whour, $wmin, $wsec) = split ':', $AoA[$y][10 +]; for (my $i = 0; $i <= $#records; $i++) { for (my $j = 0; $j <= 13; $j++) { print "$j. $AoA[$i][$j]\n"; } } #********************************* Getting error below from $ownT +ime, when using $AoA[$x][12] instead of $AoA[$x][10] **************** +************* #Convert into time $ownTime=timelocal($osec, $omin, $ohour, , $AoA[$x +][12], $months{ $AoA[$x][11] }, $year); $waitTime=timelocal($wsec, $wmin, $whour, , $AoA[$ +x+1][12], $months{ $AoA[$x+1][11] }, $year); #Calculate time difference between. my $timeDiff = $waitTime-$ownTime; $timeDiff = $timeDiff/60; $timeDiff = sprintf '%.1f minutes', $timeDiff; #Add the time difference to the end of the 'WAITER +S' line in @AoA and print it out. $AoA[$y][13] = $timeDiff; } #END IF } #END FOR-->$y } #END IF } #END FOR-->$x }




Any suggestions are much appreciated.


Thanks,
Matt

In reply to Error while using "timelocal ()" function. by mmartin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.