Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Local Copy of a member variable

by TedYoung (Deacon)
on Oct 20, 2005 at 17:09 UTC ( #501739=note: print w/ replies, xml ) Need Help??


in reply to Local Copy of a member variable

If it is a simple hash then changes to %atlas won't be seen in $self->{atlas}. Now, if the values of $self->{atlas} contain references (i.e. other hashes, arrays, object, etc) then changes to those will be seen. If you need to make a deep copy (clone) of a complex datastructure, you could use dclone method is Storable.

use Storable; my $aref = dclone($self->{atlas}); my %atlas = %$aref;

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)


Comment on Re: Local Copy of a member variable
Select or Download Code
Replies are listed 'Best First'.
Re^2: Local Copy of a member variable
by holli (Monsignor) on Oct 20, 2005 at 17:52 UTC
    From the docs of Storable:
    There is a Clone module available on CPAN which implements deep cloning natively, i.e. without freezing to memory and thawing the result.
    So I'd recomment Clone or Scalar::Util::Clone. There is also Clone::Any which is an interface for the existing clonecapable modules.

    Of course, Storable has the advantage that you can save your structures to disk (including code references).


    holli, /regexed monk/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-30 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls