in reply to dereference hash

Hello fionbarr,

Suppose you were silly unfortunate enough to have code like this:

2:56 >perl -wE "my %h = ( A => 'B' ); my $h = { A => 'C' }; say $h{A} +; say $$h{A}; say $h->{A};" B C C 3:15 >

That is, two (separate, unrelated) hashes both called h: a hash named %h, and an unnamed hash accessible via the scalar reference $h. $h{A} and $$h{A} would then be quite different things, but they would look so similar that it would be only too easy to confuse them. In a case like this, the value of the dereference syntax $h->{A} becomes apparent: it makes the dereference operation visually distinctive, and so reduces the danger of confusion.

Anyway, those of use who came to Perl from C++ find the arrow dereference syntax comfortingly familiar; it just “looks right.” ;-)

But, as always, TMTOWTDI, and YMMV.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: dereference hash
by fionbarr (Friar) on Jul 09, 2015 at 17:20 UTC
    informative reply: thanks