bangor has asked for the wisdom of the Perl Monks concerning the following question:
In this example I need to change "1:00" to "01:00" before passing to a DB query. This is how I am doing it:2014-07-12 2014-07-12 1:00 2014-07-12 01:00
It works, but it feels kludgy - any advice appreciated.sub parse_time { my $time = shift; return $time unless $time =~ m/\d{1,2}:\d{2}$/; return $time if $time =~ m/\d{2}:\d{2}$/; $time =~ s/(\d{1}:\d{2})$/0$1/; return $time; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing a date time string
by Corion (Patriarch) on Aug 02, 2014 at 16:35 UTC | |
by bangor (Monk) on Aug 02, 2014 at 16:56 UTC | |
|
Re: Parsing a date time string
by Lennotoecom (Pilgrim) on Aug 02, 2014 at 18:44 UTC | |
|
Re: Parsing a date time string
by CountZero (Bishop) on Aug 02, 2014 at 22:48 UTC |