Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Manually incrementing @ array during for

by jcb (Priest)
on Mar 17, 2020 at 01:34 UTC ( #11114371=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114371]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2020-06-05 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (40 votes). Check out past polls.

    Notices?