Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: One line assigment statement with regex match

by Codon (Friar)
on Jun 22, 2005 at 21:25 UTC ( [id://469195]=note: print w/replies, xml ) Need Help??


in reply to One line assigment statement with regex match

Do you mean something like:
my @terms = qw(one two three); @matches = grep { my $line = $_; grep {$line =~ /$_/} @terms } @lines_ +from_file;
?

Ivan Heffner
Sr. Software Engineer, DAS Lead
WhitePages.com, Inc.

Replies are listed 'Best First'.
Re^2: One line assigment statement with regex match
by jZed (Prior) on Jun 22, 2005 at 21:49 UTC
    That way will nicely return a list of lines that have at least one of the terms in them. A variant will return a list of terms that are found in at least one line:
    my @matches = grep { my $term = $_; grep{ $_=~/$term/}@lines } @terms;
    It's unclear from the description which of these (or something else) the OP wants.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-24 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found