en:perl:perlarrow
Table of Contents
Arrow Notation
Equivalence:
$array[$x]->{"foo"}->[0] = "January";
$array[$x]{"foo"}[0] = "January";
but
$array->[$x]{"foo"}[0] = "January"; (WRONG, as array is not a ref)
Derefencing
${$arrayref}[0] = ${$arrayref}->[0] = $arrayref->[0] = "January";
${$hashref}{"KEY"} = ${$hashref}->{"KEY"} = $hashref->{"KEY"} = "VALUE";
${$coderef}(1,2,3) = ${$coderef}->(1,2,3) = $coderef->(1,2,3) Subroutine call or method object
${$aref}[3] $aref->[3] instead.
${$href}{red} $href->{red}
Rule#3 replace ${ } with ->
For scalar only, recommended
Compare
${$aref} [3]
$aref->[3]
${$href} {red}
$href->{red}
replace ${ }
by ->
As we can see it can only work with scalar dereferencing @array = @{$array_ref}
$objref = new Doggie( Tail => 'short', Ears => 'long' );
$objref = Doggie->new( Tail => 'short', Ears => 'long' ); (recommended)
en/perl/perlarrow.txt · Last modified: 2021/07/12 20:19 by Bruno Manzoni