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):
To print, just do the following:my %hash = (); for my $no ( 0..$#array2 ) { if ( $array2[$no] ) { $hash{ $array2[$no] }++; } }
In general, Perl hashs are perfect for this type of requirement.foreach my $key ( sort keys %hash ) { print "$key:$hash{$key}\n"; }
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 | |
by flexvault (Monsignor) on Apr 24, 2015 at 19:07 UTC |