I have the following three assignments, of which the second one looks non-standard:
my $realRef = [1, 2, 3];
my @nonRef = [4, 5, 6];
my $nonRef = [7, 8, 9];
The second one should really be the following instead:
my @nonRef = (4, 5, 6);
When printing, all three variables contain array references and especially the same named variables only differing in @ and $ don't share the same data or overwrite each other.
Ref: ARRAY(0x1fd6a8); $VAR1 = [
1,
2,
3
];
Ref: ARRAY(0x6445d8); $VAR1 = [
4,
5,
6
];
Ref: ARRAY(0x644740); $VAR1 = [
7,
8,
9
];
Why is @nonRefcontaining an array reference at all? Is that stored in $nonRef of the symbol table entry for nonRef or something like that? And why do values of @nonRef and $nonRef don't overlap? Aren't both referencing the same symbol table entry only with different slots, ARRAY vs. SCALAR? Because both store references in the end, I would have expected that the same symbol table entry with the slot SCALAR is used.
Thanks!
[]and{}do.(LIST)confusing. That looks like the parentheses are required, but they are not:List values are denoted by separating individual values by commas ([...]):perldoc.perl.org/perldata.html#List-value-constructorsmy @a = 4,5,6;andmy @a = (4,5,6)are not equivalent because of the low precedence of,.) The doc to which you linked is phrased misleadingly, though.