Before I pass it, however, I'd like to make a copy of the entire data structure, one that will not get modified. None of the following examples do what I need, but they illustrate my train of thought...
I was certain the last example would work...What am I misunderstanding so fundamentally?# this is an arrayref or hashref containing # other arrayrefs and/or hashrefs $orig_ref; # this makes a copy of the *reference* to the same data # DOESNT WORK $copy_ref = $orig_reg; # this dereferences, then references the original data # DOESNT WORK $copy_ref = ref($orig_ref) eq 'ARRAY' ? \@{$orig_ref} : ref($orig_ref) eq 'HASH' ? \%{$orig_ref} : undef; # this derefs, copies, then refs the copy # SHOULD WORK BUT DOESNT? if(ref($orig_ref) eq 'ARRAY') { @copy = @{$orig_ref}; # deref the original @copy2 = @copy; # COPY the original data? $copy_ref = \@copy2; # ref the copied data? } elsif(ref($orig_ref) eq 'HASH') { %copy = %{$orig_ref}; # deref the original %copy2 = %copy; # COPY the original data? $copy_ref = \%copy2; # ref the copied data? }
In reply to How to copy a referenced data structure? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |