Counting array elements in Perl

前端 未结 6 1556
逝去的感伤
逝去的感伤 2021-02-02 09:29

How do I get the total items in an array, NOT the last id?

None of two ways I found to do this works:

my @a;
# Add some elements (no consecutive ids)
$a[         


        
6条回答
  •  逝去的感伤
    2021-02-02 09:46

    sub uniq {
        return keys %{{ map { $_ => 1 } @_ }};
    }
    my @my_array = ("a","a","b","b","c");
    #print join(" ", @my_array), "\n";
    my $a = join(" ", uniq(@my_array));
    my @b = split(/ /,$a);
    my $count = $#b;
    

提交回复
热议问题