in reply to Passing hashes to subs?
You can use
&callsub(%hashtopass); sub callsub { %hashread = @_; foreach $k (keys %hashread) { print "$k => $hashread{$k}\n"; } }
but I prefer to use references:
&callsub(\%hashtopass, $otherStuff); sub callsub { my ($hashref, $otherParam) = @_; # or: my $hashref = shift; if you prefer that foreach my $k (keys %{$hashref}) { print "$k => $hashref->{$k}\n"; } }
This way, you can even pass along other parameters.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Passing hashes to subs?
by Chady (Priest) on Aug 01, 2002 at 12:33 UTC | |
by crenz (Priest) on Aug 01, 2002 at 12:46 UTC |