On 25.07.2014 18:54, Chris Knipe wrote:
I have the odd (very rare) case where I am given a date in an incorrect
format. I already use Date::Parse to convert the dates to a unix
timestamp, and it’s working incredibly well. However, on the rare case
that I get incorrect dates, Date::Parse does not like them either and
errors out. The formats in question that I can’t parse basically looks like
Thu, 23 Oct 2008 12:06:48+0400
Note the lack of a space between the seconds and the timezone.
Is there a simple quick way to fix that by means of a regex?
There is, as others have pointed out.
An other way would be to use a different module, that is more relaxed
when interpreting dates/times to the underlying format, like the
`fuzzier` Time::ParseDate (https://metacpan.org/pod/Time::ParseDate).
It works for your example like in that snippet below:
perl -MDate::Parse -MTime::ParseDate -E 'my $t = "Thu, 23 Oct 2008
12:06:48+0400"; say "$t: str2time=",str2time($t),"
parsedate=",parsedate($t); $t =~ s/\+/ +/; say "$t:
str2time=",str2time($t)," parsedate=",parsedate($t)'
Thu, 23 Oct 2008 12:06:48+0400: str2time= parsedate=1224749208
Thu, 23 Oct 2008 12:06:48 +0400: str2time=1224749208 parsedate=1224749208
Greetings,
Janek Schleicher
PS: As Rob already mentioned, you should contact the author of
Date::Parse also.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/