in reply to Passing hash and hashref to sub
Your problem in in this line:
my (%hash, $conf) = @_;List assignment is greedy. So the hash takes all of @_ leaving nothing to go into $conf. If you had "use warnings" turned on then you'd get the error about using a list with an odd number of elements to create a hash.
There are (at least) three solutions:
1. Pass the parameters the other way round.
my ($conf, %hash) = @_;2. Use "pop" to get $conf.
my $conf = pop @_; my $hash = @_;
3. Pass in a hash reference instead of the hash.
my ($hash_ref, $conf) = @_;See the Copyright notice on my home node.
"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing hash and hashref to sub
by ewhitt (Scribe) on Jul 27, 2008 at 13:11 UTC |