in reply to Re: How to copy a referenced data structure?
in thread How to copy a referenced data structure?

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);

Replies are listed 'Best First'.
Re^3: How to copy a referenced data structure?
by syphilis (Archbishop) on May 22, 2007 at 06:49 UTC
    $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