Gurus,
The Camel, ( 3rd Ed. ), says,
---------------------------------------------------------------------------------------------
$listref->[2][2] = "hello"; # pretty clear
$$listref[2][2] = "hello"; # A bit confusing
This second of these statements may disconcert the C programmer, who is
accustomed
to using *a[i] to mean "what's pointed to by the ith element of a". But in
Perl, the five characters ($ @ * % &) effectively bind more tightly than
braces or brackets. Therefore, it is $$listref and not $listref[2] that is
taken to be a reference to an array.
---------------------------------------------------------------------------------------------
Now, here is how I understand the first LHS is interpreted by perl:
Rewriting, the first,
$listref->[2]->[2] = "hello"; # Adding the redundant arrow ( for
understanding )
listref ------- is a scalar which is a reference to some array's 3rd
elem
listref->[2] ------- is a scalar which is a reference to some
array's 3rd elem
$listref->[2]->[2] ------- is a scalar lvalue which is assigned string
"hello".
Now, the second LHS:
$$listref[2]->[2] = "hello"; # Adding the redundant arrow ( for
understanding )
$$listref[2] is interpreted as "$listref" is a reference to an array **
and ** $$listref[2] is
$ { $listref } [2]
( i.e. given some array @k, and $refk = \@k, then $$refk[i] is $k[i].
"Literal k always replaceable by $refk". )
Why does the text say "$$listref" is a reference??? One reference is
"$listref" and the second is "$$listref[2]" ( equivalently $ { $listref }
[2] ).
I feel there is some gap in my understanding.
------ Regards,
Atul