Where is the behavior documentation @array & # 8594; [4] or% hash & # 8594; {key} in Perl?

The last question used the syntax sigil %hash->{key} = 1; for hash access, which seems to work fine, but I would have thought it would be a syntax error.

It seems to work for arrays too:

 my @array; @array->[3] = 6; 

Is this behavior documented somewhere? I don’t remember reading it, but maybe I didn’t pay attention to it.

It seems to behave in exactly the same way:

 (\%hash)->{key} 

and not what I would suggest:

 (scalar %hash)->{key} # runtime error 
+4
source share
1 answer

It seems this has been reviewed on perlmonks: http://www.perlmonks.org/?node_id=171177

  My reading of perlop has me convinced that this is an unintended 
  syntactic feature.

 And that exactly what it is.  When using the arrow, Perl will see
 whatever is left of it as a reference.  Including if you have something
 like @l or% h.

 Note that you will get the warning
 Using an array as a reference is deprecated in Perl 5.8.0.

   Abigail
+8
source

All Articles