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

Re: Extracting elements in one array but not in another

by emazep (Priest)
on Oct 23, 2004 at 06:50 UTC ( #401778=note: print w/replies, xml ) Need Help??

in reply to Extracting elements in one array but not in another

To find elements that are in one array but not in another, there is a nice loopless solution from the Perl Cookbook which uses the delete function:
my %seen; @seen{ @original_1 } = (); delete @seen{ @original_2 }; my @original_1_only = keys %seen;
Of course there is also a loopy solution, should you prefer it:
my %seen; my @original_1_only; @seen{ @original_2 } = (); foreach (@original_1) { push(@original_1_only, $_) unless exists $seen{$_}; };
Stick with these.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://401778]
[stevieb]: I'll see how to get in touch with someone and advise that there's an issue. Thanks for helping me confiirm pryrt!
[pryrt]: also mismatches; but matches their sha1
[pryrt]: The mismatched ones have a Jan 23 2017 Last-Modified header -- I wonder if they rezipped them and forgot to update the sha1
[stevieb]: RT ticket for the csum mismatch of various versions of Strawberry Perl

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-03-29 21:06 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.