Kerplunk has asked for the wisdom of the Perl Monks concerning the following question:
Forgive me a rather elementary question about hashes. I have a hash of arguments that I would like to pass to a subroutine. Some of the arguments are themselves hashes, e.g.:
my %userHash; $userHash{$thisUID}{'name'} = 'Some Charming User'; $userHash{$thisUID}{'alias'} = 'some.charming.user'; my %args = (users => %userHash, domains => %domainHash, path => $path) +;
What I'm confused about is how to treat the hash arguments within the subroutine. This, for instance, doesn't give me the result I was expecting:
doSomethingUseful(\%args); sub doSomethingUseful { my $params = shift; my %args = %$params; my %users = $args{users}; my %domains = $args{domains}; my $path = $args{path}; if (keys %users > 1) { print("I was hoping you'd say that."); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash as Hash Value
by kennethk (Abbot) on Apr 20, 2010 at 19:39 UTC | |
|
Re: Hash as Hash Value
by toolic (Bishop) on Apr 20, 2010 at 19:33 UTC | |
|
Re: Hash as Hash Value
by lostjimmy (Chaplain) on Apr 20, 2010 at 19:37 UTC | |
|
Re: Hash as Hash Value
by Kerplunk (Acolyte) on Apr 21, 2010 at 13:21 UTC | |
by kennethk (Abbot) on Apr 21, 2010 at 14:08 UTC | |
by choroba (Cardinal) on Apr 21, 2010 at 14:04 UTC | |
by Kerplunk (Acolyte) on Apr 21, 2010 at 14:14 UTC |