I read the docs on eval but I'm still unclear on what problem it resolved.
Perhaps this simplified code will illustrate?
#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
for my $input ('05/05/2000', 'notavaliddate') {
my $date;
if (eval { $date = Time::Piece->strptime($input, '%m/%d/%Y'); 1 })
+ {
print "Parsed '$input' into '$date' with eval\n";
} else {
print "Attempted parsing of '$input' trapped by eval - life go
+es on\n";
}
if ($date = Time::Piece->strptime($input, '%m/%d/%Y')) {
print "Parsed '$input' into '$date' without eval\n";
} else {
# Next line never executed because program dies
print "Attempted parsing of '$input' trapped without eval\n";
}
}
print "Run completed OK\n"; # This line will not be reached given bad
+inputs