Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to populate a HASH using a FOR loop to a FUNCTION

by LanX (Saint)
on Dec 24, 2014 at 00:24 UTC ( [id://1111259]=note: print w/replies, xml ) Need Help??


in reply to How to populate a HASH using a FOR loop to a FUNCTION

Tl;dr but

%myHash = &makeHash($key, $val, \%myHash)

Skip the left part and you are fine, no need to reset the hash. :)

 makeHash($key, $val, \%myHash)

update

Your makeHash() is seriously broken.

Please have a look at perlref to understand how references work.

update
Better (among many things)

my $subHashRef = shift @_; $subHashRef->{$key} = $val;

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1111259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found