Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Removing elements from array (use grep!)

by Russ (Deacon)
on Aug 24, 2000 at 22:31 UTC ( [id://29488]=note: print w/replies, xml ) Need Help??


in reply to Removing certain elements from an array

Hmmm... Haven't seen a solution using the tailor-made grep.
my @array = (0,1,2,3,4,5,6,7,8,9); # The source array my %DropList = map {$_ => 1} (2,4,6,8); # A hash of the indices to rem +ove my @newarray = @array[grep {not exists $DropList{$_}} (0..$#array)]; print "@newarray\n";
Notes:
  • I am still using 5.005_57 to match a production server, so if you prefer to use exists on arrays in 5.6...
Enjoy.

Russ
Brainbench 'Most Valuable Professional' for Perl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found