http://www.perlmonks.org?node_id=1037706


in reply to Hash dereferencing in a loop

In your first version  $hashRef{$key}, you make use of %hashRef which is not declared. Change it to  $hashRef->{$key} and you should be fine. No need to do a copy as in your workaround which would be wasteful if the hash is large.

Replies are listed 'Best First'.
Re^2: Hash dereferencing in a loop
by sundialsvc4 (Abbot) on Jun 08, 2013 at 14:21 UTC

    Also, you may encounter “double-$” syntax:   $$hashref{$key}.

    The two are equivalent, and notice in this case that the -> symbol does not appear.   Recommend that you consistently use one or the other (your choice) in your programs.   (Double-$ is less common.)

    Also note that, in cases where a sequence of -> symbols would technically be required, to reference elements of a hashref that contains hashrefs, Perl allows the additional ones to be omitted.