Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Comparing 1 array that matches in 2nd array

by brx (Pilgrim)
on Jul 13, 2012 at 08:49 UTC ( [id://981582]=note: print w/replies, xml ) Need Help??


in reply to Comparing 1 array that matches in 2nd array

The two ways I understand your question:

First, you want to known what elements from @pcov match with at least one pattern from @realassert.

Second, you want to know what elements from @pcov match with all patterns from @realassert

my @pcov = ('foobar','bilbao','bobo'); my @realassert = map {quotemeta} ('foo','ba'); my $re_one = join '|',@realassert; #print $re_one; my @result_one = grep { /$re_one/ } @pcov; print "one: @result_one\n"; my @result_all = grep { my $item = $_; ! grep { $item !~ /$_/ } @realassert; } @pcov; print "all: @result_all\n"; __END__ one: foobar bilbao all: foobar

edit: You could also look at http://perldoc.perl.org/perlop.html#Smartmatch-Operator

edit2: typo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found