St?phane Payrard skribis 2004-05-18 23:14 (+0200): > I use over and over this idiom in perl5: > $a{$_}++ for @a; > This is nice and perlish but it gets easily pretty boring > when dealing with many list/arrays and counting hashes.
A3 says something about tr being able to return a histogram (a hash like your %a), A5 says something about tr being able to match more than just characters. There must be some neat trick with tr that you can use for this :) But maybe it's better to just define a histogram method for arrays. Then you can get the unique elements by doing @array.histogram.keys. But again, just having a method for that is probably a better idea (if only because with the hash, the original order is lost). Juerd