Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Easy one: removing elements of one array from another...

by indapa (Monk)
on Jun 28, 2001 at 20:33 UTC ( [id://92360]=note: print w/replies, xml ) Need Help??


in reply to Re: Easy one: removing elements of one array from another...
in thread Easy one: removing elements of one array from another...

Taken from Perl Cookbook 4.7:

#!/apps/bin/perl -w use strict; # Taken from Perl Cookbook 4.7 Finding Elements in One Array but # not another my %seen = (); # look up table my @goodWords; # words you want my @badWords=("jerk","store","king"); my @myArray=("jerry","wash","king","kong","store","when","jerk"); @seen{@badWords} = (); # build lookup table my $item; foreach $item (@myArray) { push (@goodWords, $item) unless exists $seen{$item}; } # print the contents of goodWords foreach (@goodWords) { print "$_\t"; } print "\n";

Log In?
Username:
Password:

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

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

    No recent polls found