As individual elements: $HASH{$key}[$index]
The sames values will be returned if you use $HASH{$key}->[$index]. I find this rather confusing. I looked at References quick reference and saw where tye said If the reference is in a hash or an array (and you are getting back a scalar), then you can drop the -> between the adjacent [0] and/or {KEY} parts. I'm just curious why this doesn't raise any sort of exception and if there is a correct or preferred version of the syntax? | [reply] [d/l] [select] |
| [reply] |
Preferred syntax? This is Perl, TMTOWTDI. That is, there is no preferred anything. There are, perhaps, caveats and some no-nos and some performance variations on occasion, but beyond this, do things the way you like. In this case, it's all syntactic sugar, so the interpreter ends up seeing the same thing whether there's a -> or not.
Personally, I find that $HASH{$key}->[$index] has a higher noise-to-signal ratio than $HASH{$key}[$index], so I prefer the latter.
| [reply] [d/l] [select] |