in reply to How to copy a referenced data structure?

Check out Clone. Faster than Storable, but not so flexible.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
  • Comment on Re: How to copy a referenced data structure?

Replies are listed 'Best First'.
Re^2: How to copy a referenced data structure?
by Anonymous Monk on May 22, 2007 at 06:22 UTC
    I am trying to see what the issue is that this question is trying to address. If I make a copy of a reference to a reference, and then undef that reference, the copy to original references data still exists. I know I am missing the point here, I would just like to see how.
    #!/usr/bin/perl use Data::Dumper; $ar = [ [ 1,2,3 ] ]; $copy = [ @$ar ]; undef $ar; print Dumper($copy);
      $copy = [ @$ar ];

      $copy is a reference to an array. The first (and only) element of that array is the array that $ar refers to. When you undef $ar; that has no effect on the array that $ar referred to - and hence no effect on $copy.

      Cheers,
      Rob