In that case, you have to write your own parser, hand-crafted to the specific format you're dealing with.
A general approach to doing this is:
use Time::Local; # core module as of Perl v5.000
sub parse_veryspecific_date {
my @F = grep /./, split /\D+/, shift;
return timelocal($F[2], $F[1], $F[0], # sec, min, hour
$F[3], $F[4]-1, $F[5]); # day, month, year
}
# optional -- does some quick tests to verify your hand-crafted parser
# (no automated testing; requires human verification)
sub test_date_parser {
my $parser = shift;
foreach my $string (@_) {
my $parsed = $parser->( $string );
printf "original -- %-40s parsed -- %s\n", $string, scalar(localtime($parsed));
# change this to gmtime or localtime, as needed ^^^^^^
}
}
test_date_parser(\&parse_veryspecific_date,
"12:59:00 30-3-2014",
"23:30:00 28-10-2001",
"23:30:00, 28/01/98",
);
Some notes on this:
/\D+/ has several benefits:
To convert month-names to month-numbers:
use Time::Local;
our %months;
BEGIN { %months = qw[ jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12 ]; }
sub parse_veryspecific_date {
my @F = grep /./, split /[^0-9a-z]+/i, shift;
my $month = $months{ lc(substr( $F[4], 0, 3 )) };
return timelocal($F[2], $F[1], $F[0], # sec, min, hour
$F[3], $month-1, $F[5]); # day, month, year
}
test_date_parser(\&parse_veryspecific_date, split /\n/, <<'EOF');
12:59:00 30 March 2014
23:30:00 28/Nov/2001
23:30:00, 28 January 98
EOF