perl遍历哈希的所有健和值
my %h=("001",{name,"李白",age,"18",height,"185",weight,"60kg"},"002",{name,"杜甫",age,"35",height,"175",weight,"50kg"},"003",{name,"王维",age,"50",height,"180",weight,"80kg"}); dumplist(\%h); sub dumplist { my $LIST = shift; my $legend = 0; foreach $item (sort keys %$LIST) { print "$item:\n"; my @attributes = (); my @legen = (); foreach $attr (sort keys %{$$LIST{$item}}) { push(@legen, $attr); push(@attributes, $LIST->{$item}{$attr}); print "$attr=$LIST->{$item}{$attr}\n"; } print "\n"; } }
输出结果
001: age=18 height=185 name=李白 weight=60kg 002: age=35 height=175 name=杜甫 weight=50kg 003: age=50 height=180 name=王维 weight=80kg
4556