Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Hash dereferencing in a loop

by hdb (Monsignor)
on Jun 07, 2013 at 16:42 UTC ( #1037706=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037706]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-06-24 20:58 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.