---
title: "【方法3：Perl版本】删除Map中Value重复的记录，并且只保留Key最小的那条记录"
author: "threeman"
date: "2014-06-24T10:51:00Z"
tags: []
slug: "3-perl-map-value-key"
draft: false
lastmod: "2014-07-27T09:24:37Z"
id: 2096818
url: "https://threeman.iteye.com/blog/2096818"
---

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";
}
```