Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-05-25 01:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found