Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Month '-1' out of range 0..11

by kennethk (Monsignor)
on Mar 18, 2014 at 15:32 UTC ( #1078797=note: print w/ replies, xml ) Need Help??


in reply to Month '-1' out of range 0..11

So, tracing the value back, $mon gets a value of -1 on line 35, which means it was numerically 0 from line 30. My guess, since you don't have warnings on, is that your content is different than you think going back to line 26, and so $mon is undefined going into the decrement. Can't be sure without you input file, but based on what you've posted, I'm guessing the split on 29 splits on the T in MessageDateTime rather than the T in the iso date.

See Basic debugging checklist and Use strict warnings and diagnostics or die.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: Month '-1' out of range 0..11
Select or Download Code
Re^2: Month '-1' out of range 0..11
by swissknife (Novice) on Mar 18, 2014 at 15:49 UTC

    Kenneth - Thanks for response. I doubt that it is issue with split. I have another simple codes which works well.

    #!/usr/bin/perl -w use strict; use Time::Local; my $filename = "/tmp/IN/m1.xml"; my $finaltime = &UTCtoLocal($filename); print "$finaltime \n"; sub UTCtoLocal { my ($filetoread) = @_; open (INFILE, "<$filetoread") or die "$!"; my @ActTime = map {/"(.*?)"/} grep {/MessageDateTime/} (<INFILE>); my $iso_time = join("", @ActTime); my $expected_epoch = 1 * 60 * 60 + 1 * 60 + 1; my ($date, $time) = split /T/ => $iso_time; my ($year, $mon, $mday) = split /-/ => $date; $year -= 1900; $mon -= 1; my ($hour, $min, $sec) = split /:/ => $time; my $nsec = chop($sec); my $mtime = timegm($sec, $min, $hour, $mday, $mon, $year); return ($mtime); }

    Based on these codes i prepared another one in OP as that is my main objective.

    reagarding the inputfile, i have already provided the line which has this date and keyword used in the grep command.

    any further clue?

      Did you try printing the value in $date on line 29? The answer is that some of the values are not what you think, because the following code works fine:
      #! /usr/bin/perl use strict; use warnings; use Time::Local; my $iso_time = '2014-03-18T15:41:14Z'; my $expected_epoch = 1 * 60 * 60 + 1 * 60 + 1; my ($date, $time) = split /T/ => $iso_time; my ($year, $mon, $mday) = split /-/ => $date; my $currenttime = time; # get current time from system (epoch time) my $threshold = 900; $year -= 1900; $mon -= 1; my ($hour, $min, $sec) = split /:/ => $time; my $nsec = chop($sec); my $mtime = timegm($sec, $min, $hour, $mday, $mon, $year);
      However, without your actual input file, I'm just guessing. Adding warnings and following the advice in Basic debugging checklist will help you track down the issue. Alternatively, I could help you debug if you posted your input file, wrapped in <code> tags.

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ScheduleMessage SYSTEM "../schedulev2r3/dtd/schedule-xml.dtd +"> <ScheduleMessage DtdVersion="2" DtdRelease="3"> <MessageIdentification v="8787897987897897" /> <MessageVersion v="097" /> <MessageType v="A01" /> <ProcessType v="A02" /> <ScheduleClassificationType v="A01" /> <SenderIdentification v="9090900" codingScheme="A01" /> <SenderRole v="A01" /> <ReceiverIdentification v="453543453453" codingScheme="A01" /> <ReceiverRole v="A04" /> <MessageDateTime v="2014-03-18T15:41:14Z" /> <ScheduleTimeInterval v="2014-03-13T23:00Z/2014-03-14T23:00Z" /> <ScheduleTimeSeries> <SendersTimeSeriesIdentification v="65765675765" /> <SendersTimeSeriesVersion v="001" /> <BusinessType v="A06" /> <Product v="8716867000016" /> <ObjectAggregation v="A01" /> <InArea v="10YFRkjkjkl" codingScheme="A01" /> <OutArea v="10YCHiuiuoiu" codingScheme="A01" /> <InParty v="jkkljkljlkj" codingScheme="A01" /> <OutParty v="uiouiouoiuo" codingScheme="A01" /> <MeasurementUnit v="MAW" /> <Period> <TimeInterval v="2014-03-13T23:00Z/2014-03-14T23:00Z" /> <Resolution v="PT15M" />

        I had to change the content of file as i am not supposed to share but solving the problem is also important. Please take a look and see if you can find something. alternatively i will go threough the debug steps mentioned in link. Thanks.

        my OP reference the issue which i am facing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-09-19 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (131 votes), past polls