Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: DateTime::Format::Flexible; for Log Parse with multiple formatted lines

by 1nickt (Canon)
on Mar 23, 2017 at 21:39 UTC ( [id://1185683]=note: print w/replies, xml ) Need Help??


in reply to Re^2: DateTime::Format::Flexible; for Log Parse with multiple formatted lines
in thread DateTime::Format::Flexible; for Log Parse with multiple formatted lines

Hi, I was referring to the sample data lines you included, which are not in code tags and thus are mangled. This had prevented me from trying to solve your problem ...

An SSCCE here would, as I said, contain only enough code and data to demonstrate your issue. Using the __DATA__ section in a file allows you to include data and code in the same file but keep them separate. Perfect for an SSCCE. For example:

use strict; use warnings; use feature 'say'; use DateTime::Format::Flexible; use Test::More tests => 2; my $wanted = '2017-02-20 09:30:53'; for my $string ( <DATA> ) { chomp $string; my $dt = DateTime::Format::Flexible->parse_datetime( $string ); is( $dt->strftime('%F %T'), $wanted, "with >$string<" ); } __DATA__ Mon Feb 20 09:30:53 2017 2017-02-20T09:30:53.177000
Output:
1..2 ok 1 - with >Mon Feb 20 09:30:53 2017< ok 2 - with >2017-02-20T09:30:53.177000<
(edit: updated example with OP's data)

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found