The only thing that can be passed to a function is a list of scalars. Solutions:
You could pass a reference to the hash and use that:
sub dump_hash { my ($hash) = @_; foreach my $key (keys %$hash) { print $key, '=>', $hash->{$key}, "\n"; } } dump_hash(\%hash);
You could convert the hash to a list, then recreate the hash:
sub dump_hash { my %hash = @_; foreach my $key (keys %hash) { print $key, '=>', $hash{$key}, "\n"; } } dump_hash(%hash);
In reply to Re: passing hash to subroutine
by ikegami
in thread passing hash to subroutine
by ukndoit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |