Why do all these array accessors work?
1 answer
Your first example is different from the others. This is a slice of the array - but is hidden since you are only asking for one element.
@{$test{"one"}}[0];
@{$test{"one"}}[1, 0]; # Another slice example.
Your other examples are alternative ways to remove object references in a multi-level data structure. However, using an array for de-referencing is not recommended (see perldiag ).
@{$test{"one"}}->[0]; # Deprecated. Turn on 'use warnings'.
$test{"two"}->[0]; # Valid.
$test{"one"}[1]; # Valid but easier to type.
For the last example, two subscripts next to each other are implied ->
between them. See, for example, the discussion on Arrow Rules in perlreftut.
+8
a source to share