http://qs321.pair.com?node_id=1149417


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.