Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Generic multiline grepping

by vinoth.ree (Monsignor)
on Mar 05, 2015 at 07:34 UTC ( [id://1118844]=note: print w/replies, xml ) Need Help??


in reply to Generic multiline grepping

If you can use Perl version 5.10, then there is a really easy way to do that. Just use the new smart match (~~) operator.

use warnings; use strict; use 5.10.1; my @matches = ( qr/pattern1/, qr/pattern2/, ); if( $_ ~~ @matches ){ ... }

Not tested

Update:

Tested Now,Make changes in your pattern as needed.

use strict; use warnings; use 5.10.1; my $logpattern1='rrcConnection'; my $logpattern2='measurementReport'; my $logpattern3='Event'; open(LOGFILE,"./log.txt") or die "$!"; my @file=<LOGFILE>; my $f=join("",@file); my @matches = ( qr/.*$logpattern1/, qr/.*$logpattern2/, qr/.*$logpattern3/, ); if( $f ~~ @matches ){ print("Found log marker : $logpattern1 $logpattern2 $logpattern3 in T +M500log\n"); } else{ print("Failed to find log marker: $logpattern2 $logpattern3 in $logpat +tern1 in TM500log\n"); } close(LOGFILE);

All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: Generic multiline grepping for nested pattern matching
by vasuperl (Acolyte) on Mar 06, 2015 at 05:45 UTC
    Hi Vineeth, Just now i tested. But here, initially pattern1 should be present and under pattern1 pattern2 should be present and pattern3 should be present under pattern3. whatever the code i had posted previously, its working. but the problem is, that code will work only for 3 nested pattern matching. If you had any idea please suggest me how i can do that nested pattern matching for more than 3 patterns which should be in a generic way. Thanks in advance
Re^2: Generic multiline grepping
by vasuperl (Acolyte) on Mar 06, 2015 at 05:09 UTC
    Thank you vinoth.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found