user3327369
user3327369

Reputation: 3

Count Unique values in array of arrays in perl

I have an array of arrays

push @fail_codes,[$r->[5],$row->[1]];

that looks like that

STRING_1, VALUE_1

STRING_1, VALUE_1

STRING_1, VALUE_2

STRING_1, VALUE_3

STRING_2, VALUE_1

STRING_2, VALUE_1

STRING_2, VALUE_2

I don't know in advance the FC strings neither the values.

What I would like to do is to count the items in the way that I get

STRING_1 was found n times with values VALUE_1

STRING_1 was found n times with values VALUE_2

STRING_2 was found n times with values VALUE_3 etc

Upvotes: 0

Views: 199

Answers (1)

mpapec
mpapec

Reputation: 50677

my %seen;
$seen{"$_->[0] was found %d times with value $_->[1]"}++ for @fail_codes;

printf("$_\n", $seen{$_}) for sort keys %seen;

Upvotes: 2

Related Questions