Octavian Rasnita wrote:
> I have an array with values like: > my @array=("aaa", "aaa", "bbb", "bbb", "aaa", "ccc", "aaa", "bbb", "ccc", > ....); > > I want to count how many "aaa" and how many "bbb" and how many "ccc" and how > many "..." I have in that array.I would like to > have a hash with something like: > > %hash=( > aaa => 33, > bbb => 31, > ccc => 6, > XXX => yyy > ); > > I have tried using foreach $item(@array) { > .... and here to increase a counter, but finally, I couldn't solve it. You're on the right track. Try something like this: my @array=("aaa", "aaa", "bbb", "bbb", "aaa", "ccc", "aaa", "bbb", "ccc") my %hash; foreach my $item (@array){ $hash{$item}++; } Tagore Smith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]