Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

timelocal error wired behaviour

by Anonymous Monk
on Sep 30, 2014 at 06:44 UTC ( [id://1102416]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am getting a date input from a csv file, which i want to check each date with current date, and if older than 1 month, i can do some operation on it for that entry.

I am not allowed to install extra libs so, i am not using Date::Calc and have to somehow stick to Time::Local.

Here is the snippet of my code, and suggest where I am going wrong.

Code :

if (my ($inpmm, $inpdd, $inpyyyy) = @date[1] =~ '(\d+)/(\d+)/(\d+)') { { print "@date[1] : Has been split to $certyyyy, $certmm, $certdd"; my @certdate=(0, 1, 1, $certdd, $certmm-1, $certyyyy); print "---@certdate"; # Just to see how it gets formed my $inptime=timelocal_nocheck(@certdate); print "<td>$inptime</td>"; my $timediff=$inptime - $lmtime; print "$timediff"; if ($timediff <= 2628000) { <<Go with Job>> } else { <<Skip Job>> } } else { print "Not in Format" }

Output

08/12/2016 : Has been split to 2016, 08, 12---0 1 1 12 7 2016

After this, it ubruptly ends, even when i have some 100 odd entries to go.

Thanks a lot in advance

Replies are listed 'Best First'.
Re: timelocal error wired behaviour
by Discipulus (Canon) on Sep 30, 2014 at 07:07 UTC
    hey! you have many errors in your program: is a Frankestein cut and paste experiment?!?
      1- put use strict; use warnings; and probably use diagnostic;
      2- you have two opening braces at lines 2 and 3.
      3- you have a if else else loop (big error man!) instead of if (A) elsif (B) else
      4- you are using @date[1] that is a slice of one element (if i understand) instead of $date[1]


    Also you print html tags within your output. this is another bad practice. Try to isolate the code you want to manipulate dates and run it in a sample script with use strict; use warnings;use diagnostic;

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: timelocal error weird behaviour
by hippo (Bishop) on Sep 30, 2014 at 10:09 UTC
    After this, it ubruptly ends

    That's not really surprising because there's no loop in your code. Perhaps an SSCCE would be useful to aid in the diagnosis?

Re: timelocal error wired behaviour
by CountZero (Bishop) on Sep 30, 2014 at 13:28 UTC
    I am not allowed to install extra libs
    Tell the person who stops you from installing extra modules that he is not thinking right. Does he like you to use a tried and tested module or does he want a script that does not work?

    Date and time calculations are very very complicated and full of hidden pitfalls.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1102416]
Approved by Corion
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found