I'm a fan of brevity and one-liners, so here goes... I've been trying to access one element from an array, and the man pages tell me this:
$time = (stat($file))[8]; print $time;
That works fine and dandy, but then I can't do something like:
print (stat($file))[8];
(I hate temporary variables...) Perl gives me an error (Can't use subscript on scalar at - line 1, near "8]") and I'm not quite too sure why. On the other hand, in also needing to find the length of a hash, the page for scalar tells me I can force list context by doing the following:
print ${[stat($file)]}[8];
Which works fine. So, my question is, what's the difference between the two and why doesn't the first one work? // After a little more reading, I could deduce that the second method is accessing a singular element of a resolved array reference, which is defined by a list.
In reply to Accessing Arrays and Lists by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |