Modifying Array inside While statement

A

Anno Siegel

John W. Krahn said:
(e-mail address removed) 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
 
R

robic0

John W. Krahn said:
(e-mail address removed) 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

Leaving this bomb for the next programmer is surely inspirational
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top