import-bot (20211) [Avatar] Offline
#1
[Originally posted by nkamerka]

Hi Andrew,
Can it be said that:
If the complex data structure is stored in a
reference, then there will be an arrow between
the variable name and the indices or keys
for accessing the particular variable.
Otherwise the indices or keys will start
immediately after the variable name.
eg.
$aref = { a => [ 1, 2 ],
b => [ 3, 4 ]
};
$aref->{a}[1] is 2

%h = ( a => [ 1, 2 ],
b => [ 3, 4 ]
);
$h{a}[1] is again 2.
Is this correct?
Can this be taken as a general rule?
Are there any exceptions to this?
Thanks
Nimish.
import-bot (20211) [Avatar] Offline
#2
Re: Dereference rules maybe?
[Originally posted by jandrew]

There needn't be an arrow because there is always a way to dereference
with curly braces:

$aref = { a => [ 1, 2 ],
b => [ 3, 4 ]
};
print $aref->{a}[1],"
";
print ${$aref}{a}[1], "
";

But, when you do use (or see) an arrow you can take it to mean that
everything to the left of the arrow denotes a reference, and what is
to the right is the look up. Even with multiple arrows --- because the
above is two levels of referencing:


$aref = { a => [ 1, 2 ],
b => [ 3, 4 ]
};
print $aref->{a}->[1],"
";

To the left of the first arrow is a hash reference, then we look up
key 'a' in that ref, thus the result of everything to the left of
the second arrow is an array reference which we look up index 1.
We just don't need to explicitly put arrows between any two look ups.

andrew