in reply to Parsing a date time string

Why not fix the time unconditionally?

sub fix_time { my( $time )= @_; $time =~ s/^(\d:\d\d)$/0$1/; return $time };

This replaces (if it finds) the leading single-digit number with a zero-padded number.

Replies are listed 'Best First'.
Re^2: Parsing a date time string
by bangor (Monk) on Aug 02, 2014 at 16:56 UTC
    Thanks Corion, far more elegant. I made a small adjustment so it could accept the whole string:
    sub fix_time { my $time = shift; $time =~ s/\s(\d:\d\d)$/ 0$1/; return $time; }