Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by haukex (Archbishop)
on Mar 27, 2017 at 18:07 UTC ( [id://1186112]=note: print w/replies, xml ) Need Help??


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

Please remember I am new to Perl. I am trying to understand your code examples but have not been able to get it to work in any way.

Sure, I understand, we all start somewhere :-) Sorry if I threw too many new concepts out there at once. But I also ask you to please understand that neither I nor PerlMonks are a free code writing service - I posted that working first script because I wanted to get you started with code that shows some things I'd consider best practices. Beyond that, monks will usually expect to see some efforts to learn and write code, for example you could try writing some more regexes and showing us where they are going wrong. Also, note that when you say things similar to "it didn't work", that doesn't give us enough information to help you debug - see How do I post a question effectively? and Short, Self-Contained, Correct Example.

If you're still working on getting the hang of regexes, then I recommend you get started with perlretut and perlrequick. Also, when working on regexes, it's best to use a variation of test inputs to use as test cases. Here, I will show you one way to test your regexes as you are working on them using Test::More (see Quote and Quote like Operators for information on q{} - in short, it's like single quotes). I hope it won't be too difficult to adapt for your testing. Note that the elements of the @out array correspond to $1, $2, .... Also, sites like https://regex101.com/ can help (here's something to get you started), although some of the more advanced regex syntax is not compatible with Perl.

use warnings; use strict; use Test::More; # this is the regex we're working on my $regex = qr/^ \s* (\d+) \s* \[(\d+)\] \s+ (\S+) \s+ \[(.+?)\] \s* ( +\w+): \s* (.*?) \s* $/x; { ok my @out = # inside the q{} is the test input string q{ 20848[30892] 0000000000000000 [DM_MQ_I_DAEMON_START]info: + "Message queue daemon (tid : 27944, session 0102b20d80000456) is st +arted sucessfully." } =~ $regex; is_deeply \@out, # inside the [] is the expected output (capture group matches) [ '20848', '30892', '0000000000000000', 'DM_MQ_I_DAEMON_START', 'i +nfo', q{"Message queue daemon (tid : 27944, session 0102b20d80000456) is + started sucessfully."} ] or diag explain \@out; } # ... add more test cases here! done_testing;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found