閱讀385 返回首頁    go 阿裏雲 go 技術社區[雲棲]


【方法3:Perl版本】刪除Map中Value重複的記錄,並且隻保留Key最小的那條記錄

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


最後更新:2017-04-03 07:57:13

  上一篇:go 關於webview調用js出現has no method &#39;toString&#39;
  下一篇:go windows 模擬按鍵與鼠標