icemouse210写了一个Perl版本的,发挥了脚本高度封装的优势。我把代码贴出来,供大家参考分享。
#!/user/bin/perl -w use English; use strict; use warnings; my %test_hash=( "A" => '1', "B" => '2', "C" => "2", "D" => "3", "E" => '3', ); my @keys = keys %test_hash; my %count = (); my @unique_keys = grep { ++$count{$test_hash{$_}} < 2; } sort @keys; foreach my $k (@unique_keys) { print "$k => $test_hash{$k}\n"; }