Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: how to rm an element from an array?

by Revelation (Deacon)
on Oct 28, 2002 at 03:30 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://208438]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found