Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by ambrus (Abbot)
on Dec 04, 2015 at 22:26 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found