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

I did use the code tags. it works fine on my browser, just small window and the download link works on all of them.
So instead of one continuous string how would you use while for this code in a loop?
I am not sure what you are asking for, for SSCCE, I did what I believe I was told for the SoPW and I did give all code (properly as I understand it) and example lines, What am I missing/not understanding.
Where is a data section?
Part of my problem is I am unsure of the date handling code due to DateTime::Format::Flexible; is new to me and I have not understood the documentation completely which is why I am asking in the first place. Please don't take this as me being an ass. I just don't understand and need clarification.

  • Comment on Re^2: DateTime::Format::Flexible; for Log Parse with multiple formatted lines

Replies are listed 'Best First'.
Re^3: DateTime::Format::Flexible; for Log Parse with multiple formatted lines
by Marshall (Canon) on Mar 23, 2017 at 22:08 UTC
    You need to use code tags, not only for the program code, but also for the the data that the program is supposed to read. In the text of your question, please use code tags to display:
    Mon Feb 20 09:31:25 2017 [INFO] [AGENTEXEC] Error Description.
    code tags also put things into a fixed width font. Your program is unable to parse this line:
    2017-02-20T09:30:53.177000 20[] 0000000000000000 Error Description

    In Perl, it is possible to define a file that is contained within the program code itself! This is called a DATA segment. A simple example:

    #!/usr/bin/perl use strict; use warnings; while (<DATA>) { print; } __DATA__ Some example lines that could be in a file
    The __DATA__ segment is a pre-opened file handle. There are ways to put multiple input files within the code, but a DATA segment for a single file is the most often used.

    It is not clear to me what the desired output is. Please include an example of that in your post.

Re^3: DateTime::Format::Flexible; for Log Parse with multiple formatted lines
by 1nickt (Canon) on Mar 23, 2017 at 21:39 UTC

    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.