in reply to Re: Counting unique elements in an array
in thread Counting unique elements in an array
although many do not like using map in a void context others find it more intuitive to operate on the entire array than looping through it's elements
It's not that I "do not like" map in void context, I just think it's redundant with a plain for loop. Now, grabbing the return values from map is not redundant with for, so I use it in those cases. As for your specific example, I would write that map line as:
$sum{$_}++ for @array;
Which is shorter, contains less syntax, and puts the most important part of the code at the beginning of the line.
|
|---|