XP is just a number | |
PerlMonks |
Re: Assigning a parsed date to a variableby 1nickt (Canon) |
on Mar 30, 2017 at 21:47 UTC ( [id://1186549]=note: print w/replies, xml ) | Need Help?? |
Hi, you said: unless there is a more efficient way of doing it Unless you are working on your regexp-fu, I would suggest not using a regexp to parse dates. Efficiency extends to future readability of your code. Just use DateTime::Format::Strptime to make a parser with the format you want and eval to see if the string parses into a DateTime object. Here's an SSCCE that demonstrates: Edit: Or, declare the parser without the on_error attribute, and then you can use the DateTime object, if you can parse a date from your string. Presumably you want to use the date after you've found it.
Hope this helps!
The way forward always starts with a minimal test.
In Section
Seekers of Perl Wisdom
|
|