in reply to Array Reference Question
The difference is shown by the following example
use strict; use warnings; use Data::Dumper; my @x = (1,2,3); my $y; @$y = @x; $x[1] = 9; print Dumper $y; $y = \@x; $x[1] = 10; print Dumper $y;
As you can see, in the second code, the $y is a reference to $x, so they share the same data. In the first case, the $y is a reference to an anonymous array, which has a copy of the data in $x.
Think of the operation @a = @b. This is creating a copy of any array. That is what is happening in the first case (with @$y = @x.
The second case is a $x = \@y, which is assigning a reference to a scalar, so there is no array copying. Only a scalar (the reference to @b) is being copied.
|
|---|