How to implement a search for identical records in a text array (@sgn_str). There are signatures in the array, you need to check that there are no two or more identical signatures in it.

    4 answers 4

    those. need to remove duplicates?

    my @new_list; # массив куда будут помещены "отфильтованные" значения my @list ; #исходный массив my %seen; #хеш для работы @new_list = grep {$_ && !$seen{$_}++} @list ; 
    • Not! It is necessary to check if there are identical records in it! If there is a repetition, then not all the signatures are collected ... Although .. Then you can compare the number of records in the new and old array. If it is the same, then there are no duplicates !!! - Vitaly Vladimirov

    Or so:

     my @data = (1,2,3,3,4,4,4); my %values; $values{$_}++ foreach @data ; 
    • Accordingly, the% values ​​will be the number of times each line occurs: foreach my $ key (sort keys% values) {print "$ key: $ values ​​{$ key} \ n"; } - user6550

    And if you want to count the number of identical values? for example: my @data = (1,2,3,3,4,4,4); my% values; $ values ​​{$ _} ++ foreach @data ; 1 - 1 3 - 2 4 -3

    • figured out) - den1s
     use List::MoreUtils "uniq";my @unique = uniq @all ;