Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: parse hash to sub

by bunnyman (Hermit)
on Jul 15, 2003 at 17:30 UTC ( #274488=note: print w/replies, xml ) Need Help??


in reply to parse hash to sub

 my %packages = $_[1];

You can't do this. When you passed the %new_db to the sub, it got broken apart into a list, which looks like (1, 'gedit', 2, 'ppp'). So when you write $_[1] you are getting the first thing in that list, but you wanted to get the whole thing.

You could fix it by writing @_[1..$#_] to get the whole thing, but that's pretty ugly. You could also write my ($count, %packages) = @_; which is less ugly and does the same thing.

The best thing is to not even break the hash into a list at all. You can do that by passing a reference to the sub. Read about references at http://perldoc.com/perl5.8.0/pod/perlreftut.html

Log In?
Username:
Password:

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

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












    Results (62 votes). Check out past polls.

    Notices?