All the Perl that's Practical to Extract and Report

Navigation

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Without JavaScript enabled, you might want to
use the classic discussion system instead. If you login, you can remember this preference.

Please Log In to Continue

As I understand it, the funny character demarks the context of the variable. I haven't played around with this (yet), but what if the array was a list of refs to other arrays? Would that be @array[0] or @$array[0]? If the former, then all the more reason the funny character helps, as it denotes the context.

@$array[0] binds the @ more tightly than the [0], so it expects $array to be an array ref, which you're de-referencing, rather than $array[0] being the array ref. Except it doesn't work, because as you know, you don't say @x[0], you say $x[0], so when you say @$array[0], it thinks you're dereferencing $array, not @array, and $array doesn't exist (well it might, but it's not what you meant).

Now @{$x[0]} will give you the de-referenced array in the first entry in the @x array. Because here we're being explicit about the precedence using curlies to bind it. But it can get a bit more confusing, because say you wanted the second entry in the first array? i.e. given:
my @x = ([1,2], [3,4]);

So you want the "2" above. Now that's:
my $two = @{$x[0]}[1];

But we got a scalar! Now what happened to that "symbol means context" thing here? Screwey, huh?