Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: convert a given YYYY-MM-DD to epoch time

by ambrus (Abbot)
on Dec 04, 2015 at 17:26 UTC ( #1149417=note: print w/replies, xml ) Need Help??

in reply to convert a given YYYY-MM-DD to epoch time

Are you sure that this is the exact code you're running? The line numbers don't seem to match.

In any case, if it is the same code, then you never seem to handle the case when the regular expression actually matches. Maybe your input file contains lines where it doesn't match. Use an if statement around the assignment, such as

if (($yyyy, $mm, $dd) = ($date =~ /(\d+)-(\d+)-(\d+)/)) { $epoch_seconds = timelocal(0, 0, 0, $dd, $mm, $yyyy-1900); $strings = localtime($epoch_seconds); print "$date : $epoch_seconds\n" if $date lt $cutoff; } else { # do something here when the line does not contain a date }

You might also want to use some anchors in the regex if you want to make sure the whole line matches.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2023-12-09 17:33 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (38 votes). Check out past polls.