Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

by ambrus (Abbot)
on Dec 04, 2015 at 22: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
Node Status?
node history
Node Type: note [id://1149417]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2020-10-01 02:06 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (172 votes). Check out past polls.