ibanix has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to remove $item from @array inside the if (!$return) block.my @array; foreach my $item (@array) { my $return = foo($item); if (!$return) { print "$item returned false\n"; next; } other_stuff(); }
but that seems a waste, as I have to declare another array. Is there a simple way to remove a given $item from an @array?my @array; my @newarray; foreach my $item (@array) { my $return = foo($item); if (!$return) { print "$item returned false\n"; push @newarray, $item; next; } other_stuff(); } @array = @newarray; # or whatever...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing Items from an Array
by BrowserUk (Patriarch) on Dec 03, 2002 at 21:59 UTC | |
|
Re: Removing Items from an Array
by kabel (Chaplain) on Dec 03, 2002 at 21:33 UTC | |
by ibanix (Hermit) on Dec 03, 2002 at 21:41 UTC | |
by UnderMine (Friar) on Dec 03, 2002 at 21:52 UTC | |
by graff (Chancellor) on Dec 05, 2002 at 03:50 UTC | |
|
Re: Removing Items from an Array
by sauoq (Abbot) on Dec 03, 2002 at 22:06 UTC | |
|
Re: Removing Items from an Array
by Mr. Muskrat (Canon) on Dec 03, 2002 at 21:45 UTC | |
|
Re: Removing Items from an Array
by ibanix (Hermit) on Dec 03, 2002 at 21:35 UTC |