in reply to Re: Multiple Levels of Array Dereferencing Have me Stumped
in thread Multiple Levels of Array Dereferencing Have me Stumped

Yes, but is it a useful copy? The question was about an extra reference-dereference pair that makes a copy of a copy. What do you get for that work?

Just about nothing. There is no reason that I can see to prefer:

sub foo { my @foo = @{[@{$_[0]}]}; # etc }
over
sub foo { my @foo = @{$_[0]}; # etc }
In fact try this:
my $bar = ["hello", "world"]; foo($bar); print "$bar->[0]\n"; sub foo { # Make my copy. my @foo = @{$_[0]}; # Try to mess up the first element. $foo[0] =~ s/h/H/; }
See? You get a private copy already.

Replies are listed 'Best First'.
RE: RE (tilly) 2: Multiple Levels of Array Dereferencing Have me Stumped
by cianoz (Friar) on Nov 05, 2000 at 23:28 UTC
    I was trying to explain "what" that code does and not "why"
    however you'r right: my (@list) = @{[@{$_[0]}]}; will just build an extra (useless) copy, i didn't verified it..
      It looks to me like metaperl had already figured that out and the confusion was the belief that the extra copy had to do something useful.

      Which it doesn't.