Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Parsing Timestamp with extra spaces

by johngg (Canon)
on May 12, 2020 at 13:45 UTC ( [id://11116714]=note: print w/replies, xml ) Need Help??


in reply to Parsing Timestamp with extra spaces

I would just modify any single digits before parsing.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @dateStrs = ( q{Fri May 8, 2020 - 11:12:13}, q{Fri May 15, 2020 - 14:08:17}, q{Sat May 16, 2020 - 7:31:22}, q{Mon Jun 1, 2020 - 6:24:18}, ); s{(?<=\D)(\d)(?=\D)}{ sprintf q{%02d}, $1 }eg for @dateStrs; say for @dateStrs;' Fri May 08, 2020 - 11:12:13 Fri May 15, 2020 - 14:08:17 Sat May 16, 2020 - 07:31:22 Mon Jun 01, 2020 - 06:24:18

Perhaps the problem is more complex than stated in the OP but this seems to work.

Update: A version that copes properly with extra spaces, the first version didn't.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @dateStrs = ( q{Fri May 8, 2020 - 11:12:13}, q{Fri May 15, 2020 - 14:08:17}, q{Sat May 16, 2020 - 7:31:22}, q{Mon Jun 1, 2020 - 6:24:18}, q{Fri May 8, 2020 - 11:12:13}, q{Fri May 15, 2020 - 14:08:17}, q{Sat May 16, 2020 - 7:31:22}, q{Mon Jun 1, 2020 - 6:24:18}, ); s{(\s+\d)(?=\D)}{ sprintf q{ %02d}, $1 }xeg for @dateStrs; say for @dateStrs;' Fri May 08, 2020 - 11:12:13 Fri May 15, 2020 - 14:08:17 Sat May 16, 2020 - 07:31:22 Mon Jun 01, 2020 - 06:24:18 Fri May 08, 2020 - 11:12:13 Fri May 15, 2020 - 14:08:17 Sat May 16, 2020 - 07:31:22 Mon Jun 01, 2020 - 06:24:18

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found