Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 wandering the Monastery: (2)
As of 2024-04-25 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found