
Laurent_R
Veteran
/ Moderator
Oct 16, 2013, 2:22 PM
Post #3 of 4
(3157 views)
|
Re: [Zhris] Count number of occurrences in list
[In reply to]
|
Can't Post
|
|
I frankly would use the first or third of the solutions proposed by Chris, but would tend to avoid the grep version because, although it works perfectly, it is using the grep function for something that it is not really designed to do and is therefore a bit more complicated to understand. And if you want to print the resulting hash in the way described in the OP, you might do something like this:
print "{", (join ",", map {" $_ => $hash{$_}"} sort keys %hash), " }"; which should happily print:
{ a => 3, b => 3, c => 3, d => 1, e => 2 }
|