Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Perl:how to find multiple strings

by jwkrahn (Abbot)
on Apr 08, 2011 at 17:30 UTC ( [id://898404]=note: print w/replies, xml ) Need Help??


in reply to Perl:how to find multiple strings

You need a program something like this:

#!/usr/bin/perl use strict; use warnings; my $log = 'log'; @ARGV == 2 or die "usage: $0 TAB_1 TAB_5\n"; my ( $TAB_1, $TAB_5 ) = @ARGV; open my $HAN, '<', $log or die "Cannot open '$log' because: $!"; while ( <$HAN> ) { next unless /^8=/; print "[+] FOUND $TAB_1 and $TAB_5 in\n", "-----------------------\n", $_ if / 1=\Q$TAB_1\E / && / 5=\Q$TAB_5\E /; }

Replies are listed 'Best First'.
Re^2: Perl:how to find multiple strings
by auto_w (Novice) on Apr 08, 2011 at 18:04 UTC
    still doesn't make any output --does it work for you?

      It apparently doesn't work because the string "5=8(" is not in any of the lines.

        correct but there is 5=8^A

        Now it works -i just changed to --open (my $HAN, $logg) question --how to add else statement if match not found, i tried adding else but that didn't work out for me ... So far that is the best code i've seen so compact and powerfull---WELL DONE!!!! i wasn't aware of next function...and your ARGV is so nice!!!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-29 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found