in reply to remove current element out array

If you want to know the current element in a foreach loop, you could easily switch to a for loop. In this case $i is your array index.

for ($i = 0; $i < scalar @array; $i++) { ... }

Here's something else you could do. As always, there's more than one way to do it.

sub removeJunk { my @stuff = @_; my (@keepers); while (my $value = pop @stuff) { @keepers = (@keepers, $value) if ($value =~ /^test\s/); } return @keepers; }

If you have a really big array, you will want to use references.

Replies are listed 'Best First'.
RE: Re: remove current element out array
by Anonymous Monk on May 20, 2000 at 01:19 UTC
    You wouldn't want to use the for loop with a splice - that would incrememnt the $i counter AND move up all the array's elements, causing an elemnet to be skipped.