in reply to passing hash to subroutine
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);
|
|---|