LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi according to the perldocs of Tie::Hash this works
sub STORE { warn "Storing data with key $_[1] at $_[0].\n"; $_[0]{$_[1]} = $_[2] }
and in my tests it does, but I don't really understand why, because $_[0] is supposed to be a reference(!) and is not properly dereferenced here. Looking into the source of Tie::Hash reveals the expected usage.
package Tie::StdHash; ... sub TIEHASH { bless {}, $_[0] } sub STORE { $_[0]->{$_[1]} = $_[2] }
I'm confused, is there any aliasing magic in $_[0] making it act as a non-refrence hash variable?

Cheers Rolf

Replies are listed 'Best First'.
Re: Confused about $self in Tie::Hash
by choroba (Cardinal) on Oct 12, 2011 at 15:48 UTC
    The arrow is optional after a hash key or array index, it is mandatory only after the scalar containing a reference. Thus,
    $h_ref->{key}; $a_ref->[1]; $h_ref->{key}{deeper}; $h_ref->{key}[2]; $a_ref->[0][1]; $a_ref->[1]{inside}; $arr[0][1]; $hash{key}{deeper};
    are all OK.
      Argh, thanks you're right.

      ( I stopped looking at $_[0] as an array element of @_. )

      Cheers Rolf