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

Re: Match string in array

by polypompholyx (Chaplain)
on Oct 03, 2005 at 19:09 UTC ( #497024=note: print w/ replies, xml ) Need Help??


in reply to Match string in array

You probably want something like this: use a hash to record all the items in the first array, then grep for items in the second array that you haven't already seen:

my %seen_in_1; $seen_in_1{$_}++ for @rray1; my @in_2_but_not_1 = grep { not $seen_in_1{$_} } @rray2;

Or, to avoid duplicates:

my %seen_in_1; $seen_in_1{$_}++ for @rray1; my $seen_in_2_but_not_1; $seen_in_2_but_not_1{$_}++ for grep { not $seen_in_1{$_} } @rray2; my @in_2_but_not_1 = keys %seen_in_2_but_not_1;


Comment on Re: Match string in array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2015-07-07 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls