Perl: the Markov chain saw | |
PerlMonks |
Accessing Arrays and Listsby Anonymous Monk |
on Jun 27, 2002 at 18:28 UTC ( [id://177805]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: 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:
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.
Back to
Seekers of Perl Wisdom
|
|