Re: Modifying Array inside While statement



John W. Krahn <krahnj@xxxxxxxxx> wrote in comp.lang.perl.misc:
> ced@xxxxxxxxxxxxxxxxxxxxx wrote:

> > for ( reverse 0..$#my_array) {
> > unshift @new_array, splice @my_array, $_, 1 if $my_array[$_] =~
> > /new/;
> > }
>
> Or:
>
> push @{ /new/i ? \@new_array : \@my_array }, $_ for splice @my_array;

Ah... splice with just an array clears the array and returns a copy. I never
noticed.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.