Welcome to the monastery!
You can simply convert the array into a hash.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array = qw(dog cat sheep dog dog cat); my %hash; $hash{$_}++ for @array; # dump the hash to stdout print Dumper( \%hash ) . "\n"; # print each key-value pairs for (sort keys %hash) { print "$_ -> $hash{$_}\n"; }
In reply to Re: How do I count the number of occurrences of a string in an array?
by pme
in thread How do I count the number of occurrences of each string in an array?
by aschwa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |