Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: parse hash to sub

by Trimbach (Curate)
on Jul 15, 2003 at 17:24 UTC ( #274482=note: print w/replies, xml ) Need Help??


in reply to parse hash to sub

Because Perl automatically flattens hashes and arrays that are passed to subs, my %packages = $_[1]; doesn't access the entire %new_db hash, but only the first key of %new_db, which is why you're getting the odd number of elements error.

Do it this way instead:

new_packages($fcount,\%new_db); sub new_packages { my %packages = %{$_[1]}; ...
By passing %new_db as a hash-reference, $_[1] refers to the hash-ref, which is then de-referenced into the %packages hash like you want.

Most all of the time if you need to pass an array or hash into a sub you'll want to pass it by reference, not by value. :-)

Gary Blackburn
Trained Killer

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2022-01-22 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?