in reply to How do I count the number of occurrences of each string in an array?
"... rather than just getting a quick fix to the problem"
Yes sure. But i guess that what BrowserUK answered in 2002 might be of interest ;-) I modified the code a bit:
#!/usr/bin/env perl use strict; use warnings; my @array = qw(dog cat sheep dog dog cat); my ( $temp, $count ) = ( "@array", 0 ); ( $count = $temp =~ s/($_)//g ) and printf "%2d:%s\n", $count, $_ for +@array; __END__ karls-mac-mini:monks karl$ ./1138451.pl 3:dog 2:cat 1:sheep
Please see Re: Count duplicates in array. for the original code.
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|