in reply to Re: Processing arrays 2 elements at a time (TIMTOWTDI)
in thread Processing arrays 2 elements at a time (TIMTOWTDI)
So don't make your copy first. It's a reference after all, which in this case makes life easy.
This way we build our new array (while the one gets bigger, the other gets smaller), then we simply change what the reference points to.my @copy; while (@$r) { push @copy, [ shift @$r, shift @$r ]; } $r = \@copy;
In Section
Meditations