Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl:how to find multiple strings

by wind (Priest)
on Apr 08, 2011 at 16:19 UTC ( [id://898389]=note: print w/replies, xml ) Need Help??


in reply to Perl:how to find multiple strings

Use the block form of grep and separate your regexes:
my $matches = grep {/1=$TAB_1/ && /5=$TAB_5/} @contents ;
Also, the question is, are those variables supposed to be literal strings? If so, then you need to use quotemeta or \Q..\E to escape regular expression special characters:
my $matches = grep {/1=\Q$TAB_1\E/ && /5=\Q$TAB_5\E/} @contents ;
And finally, if those strings are supposed to match in a particular order, then just put them back in a single regex with .* between them, not &&:
my $matches = grep {/1=\Q$TAB_1\E.*5=\Q$TAB_5\E/} @contents ;

Log In?
Username:
Password:

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

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

    No recent polls found