What's the most efficient way to check for duplicates in an array of data using Perl?

前端 未结 7 1582
花落未央
花落未央 2020-12-05 14:26

I need to see if there are duplicates in an array of strings, what\'s the most time-efficient way of doing it?

7条回答
  •  一整个雨季
    2020-12-05 15:08

    Not a direct answer, but this will return an array without duplicates:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my @arr = ('a','a','a','b','b','c');
    my %count;
    my @arr_no_dups = grep { !$count{$_}++ } @arr;
    
    print @arr_no_dups, "\n";
    

提交回复
热议问题