in reply to Re^2: Manually incrementing @ array during for
in thread Manually incrementing @ array during for

Several other monks have been suggesting ways to handle this that end up modifying @array. If your part of the program receives a reference to @array, you can use the dclone method from the core module Storable to copy the array and then mangle the copy however you want.

Adapted from the Storable POD:

use Storable qw(dclone); # ... my $arrayref = dclone($provided_arrayref);

As long as @array is small enough to copy, this should be very efficient; Storable is an XS module.

Replies are listed 'Best First'.
Re^4: Manually incrementing @ array during for
by Aaronrp (Scribe) on Apr 11, 2020 at 20:45 UTC
    If the array is an array of scalars (and none of the elements are references), of course, one can just do @copy = @original and it will work fine.