Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: how to rm an element from an array?

by Revelation (Deacon)
on Oct 28, 2002 at 03:30 UTC ( #208438=note: print w/replies, xml ) Need Help??


in reply to how to rm an element from an array?

I don't do this personally, but the delete function can be used, instead of grep, if you want to preserve the array indices:
perldoc -f delete
Given an expression that specifies a hash element, array element, hash slice, or array slice, deletes the specified element(s) from the hash or array. In the case of an array, if the array elements happen to be at the end, the size of the array will shrink to the highest element that tests true for exists() (or 0 if no such element exists).
for (0..$#arr) {delete($arr[$_]) if $arr[$_] eq $var;};
I'd use grep, otherwise (IO has provided an example of how to use grep).

Gyan Kapur
gyan.kapur@rhhllp.com

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2021-01-25 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?