note
roboticus
<p>[ree]:</p>
<p>Just a bit of clarification on [RichardK|RichardK's] answer: Notice how it says 'between' subscripts. So after the first one, it's always optional. Before the first one, though, you need to tell perl that you're accessing a value through a reference, and there are two ways you can do so. Either add a '$' to the front, or use a '->' after the scalar:</p>
<c>
my @a = ( 1, 4, 9, 16); # squares
my @b = ( 1, 8, 27, 64); # cubes
my @c = ( \@a, \@b ); # two arrays
my $d = \@a;
my $e = \@c;
# OK: @a is an array
print $a[0];
# Wrong: $d is a reference, not an array!
print $d[0];
# OK: Both of these are fine, though
print $d->[0];
print $$d[0];
# with multiple subscripts:
print $e->[0]->[0];
print $e->[0][0]; # same as above, since -> is optional between subscripts
print $$e[0][0]; # also same as above
</c>
<p>You may find yourself preferring an extra '$' at the front (which is what I usually use) or using the '->' (which I use when I want to alert myself to the fact that I'm using a reference). You need to be comfortable with both, since you'll frequently encounter both notations.</p>
<p><b>Update:</b> D'oh! I bungled my variable declarations, as caught by [roho] and explained by [Athanasius]. Corrected (converted square brackets to parenthesis in first three lines).</p>
<p>...[roboticus]</p>
<p><i>When your only tool is a hammer, all problems look like your thumb.</i></p>
1010691
1010691