Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Deleting specific element in array in FOREACH loop

by hgolden (Pilgrim)
on Sep 15, 2006 at 19:50 UTC ( [id://573236]=note: print w/replies, xml ) Need Help??


in reply to Deleting specific element in array in FOREACH loop

Grep is god's gift to this situation. Check out grep. Basically, you can write a subroutine that takes the array element as an input and returns true or false, true if it should be included.

Then you write a version of  @newarray=grep {&subroutine($_)} @oldarray. The new array will only contain the elements that the subroutine returned true for.

Hays

Replies are listed 'Best First'.
Re^2: Deleting specific element in array in FOREACH loop
by awohld (Hermit) on Sep 15, 2006 at 20:36 UTC
    Ahhh, I never thought about using a subroutine in the grep expresssion! That's really good info.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2025-05-24 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.