in reply to Passing hashes to subs?
foo (%hash); sub foo { my %passed_hash = @_; # do stuff }
...which only workes if the hash is the only argument you have (or the last one..). If it is not, or you have more than one hash to pass, and your subroutine is seen at sompile ime, you can use this elegant solution:
sub foo (\%$); foo (%hash, $arg); sub foo (\%$) { my $hash_ref = shift; my $passed_arg = shift; my $passed_hash = %$hash_ref; # do stuff }
The second example provides a prototype for the subroutine. How these work can be read in perlsub.. But to give you some clue: It automatically converts the hash into a reference..
Regards,
-octo
|
---|