Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Can't seem to match from one varibale to next one.

by Ben328 (Novice)
on Sep 16, 2012 at 22:52 UTC ( [id://993941]=note: print w/replies, xml ) Need Help??


in reply to Re: Can't seem to match from one varibale to next one.
in thread Can't seem to match from one varibale to next one.

Thanks Kenosis. This is great. On your solution how do i define other variables within the line though? Basically, I also wanted the capability to pull any portion of the line as a variable so that I can compare each variable seperately later on.

For ex: I want to define variable for ACTIVE ExecuteThread: and so forth as well. Do i do that as follows:

push @infos, $1, $2, $3, while $data =~ / \ (.+?) \ \s+ \ (.+?) \ ... and so forth

Does this makes sense? Hopefully, i am asking the right question. In any case, I have been helped tremendously already. Thanks,
  • Comment on Re^2: Can't seem to match from one varibale to next one.

Replies are listed 'Best First'.
Re^3: Can't seem to match from one varibale to next one.
by Kenosis (Priest) on Sep 17, 2012 at 00:08 UTC

    You're most welcome, Ben328! Am glad it worked for you...

    The following will capture all four fields from each record of your data set, so you can work with them as needed:

    use strict; use warnings; { local $/; open my $fh, '<', 'logFile.txt' or die $!; my $data = <$fh>; while ( $data =~ / (?=\[\d{4}) # Start record \[(?<date>.+?)\]\s* \[(?<active>.+?)\]\s* ExecuteThread:\s*(?<executeThread>.+?) INFO\s*-\s*(?<info>.+?) (?=\[\d{4}|\Z) # End record /gsx ) { print 'date: ', "$+{date}\n"; print 'active: ', "$+{active}\n"; print 'executeThread: ', "$+{executeThread}\n"; print 'info: ', "$+{info}\n"; } }

    Output:

    date: 2012-09-14 16:55:22,497 active: ACTIVE executeThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)' +(com.this.perl.seems.kinda.Cool:di sconnectCORBA:154) info: Well this is just one line text date: 2012-09-14 16:55:22,498 active: ACTIVE executeThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)' +(com.this.perl.seems.kinda.Cool:di sconnectCORBA:154) info: Well this is just multiple line text With formats Like this ***** Some other text **** then some more text on another line date: 2012-09-14 16:55:22,499 active: ACTIVE executeThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)' +(com.this.perl.seems.kinda.Cool:di sconnectCORBA:154) info: Well once again this is part starts with bracket and blah blah b +lah

    The regex gets a bit 'ugly,' but manageable. Named captures were used, so $+{info} contains the single or multiline INFO text.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-20 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found