in reply to Elements in array
I had a hell of a time trying to figure this out, getting each total one less than it should have been, until I thought to use a prefix ++ instead of postfix. Code and learn, I guess. HTH.@array = qw/a b a c b d e c a/; %hash = map { $_ => ++$hash{$_} } @array; + printf "%s => %s\n", $_, $hash{$_} foreach sort keys %hash; --------- a => 3 b => 2 c => 2 d => 1 e => 1
--
Mephit (See my home node for my rant about Opera and PerlMonks, and my earliest nodes.)
|
---|