如何在perl子函数中传递hash

2024-11-15 13:34:07
推荐回答(2个)
回答(1):

sub test { my %hash = @_; print "$_ => $hash{$_}$/" foreach keys %hash;}my %h = ( A => 100, B => 200, C => 300 );test(%h);

回答(2):

1
2
3
4
5
6
7
sub test {
my %hash = @_;
print "$_ => $hash{$_}$/" foreach keys %hash;
}

my %h = ( A => 100, B => 200, C => 300 );
test(%h);