Arrow dereferencing

References to arrays, hashes, and subroutines can be dereferenced using the -> operator. This operator dereferences the expression to its left, which must resolve to an array or hash and accesses the element represented by the subscripted expression on its right. For example, these three statements are equivalent:

$$arrayref[0] = "man";
${$arrayref}[0] = "man";
$arrayref->[0] = "man";

The first statement dereferences $arrayref first and finds the first element of that array. The second uses braces to clarify this procedure. The third statement uses the arrow notation to do the same thing.

The arrow dereferencing notation can be used only to access a single scalar value. You cannot use arrow operators in expressions that return either slices or whole arrays or hashes .

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.