in reply to Compare elements from two arrays and count

Welcome skalman,

Maybe a hash is what you want. Build the hash so that the names from 'array 2' are the keys and the key value is the counter, i.e. (untested):

my %hash = (); for my $no ( 0..$#array2 ) { if ( $array2[$no] ) { $hash{ $array2[$no] }++; } }
To print, just do the following:
foreach my $key ( sort keys %hash ) { print "$key:$hash{$key}\n"; }
In general, Perl hashs are perfect for this type of requirement.

UPDATE:Fixed as 'perl' Laurent_R :-)

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Compare elements from two arrays and count
by Laurent_R (Canon) on Apr 24, 2015 at 17:14 UTC
    This should be reading array2 (where there are multiple occurrences of the users) rather than array1 for populating the counter hash, shouldn't it?

    Je suis Charlie.

      Laurent_R,

      You are correct, as usual!

      Regards...Ed

      "Well done is better than well said." - Benjamin Franklin