in reply to Use of grep with arrays/hashes

I prefer to use the map function for this type of hash population

map {$fields{$_}++} @fields;

This is not much different than merlyn's; his is probably faster though. I wonder why ...

Replies are listed 'Best First'.
(ar0n) Re (2): Use of grep with arrays/hashes
by ar0n (Priest) on May 24, 2001 at 06:49 UTC
Re (tilly) 2: Use of grep with arrays/hashes
by tilly (Archbishop) on May 24, 2001 at 08:05 UTC
    Of the two bad idioms, abusing map is worse because if your function returns multiple values per term and you are on any Perl before 5.6.1, the effort of constructing the return list is quadratic.

    But map and grep work out the same in this case, and the potential difference is largely irrelevant because both run more slowly than simple looping and waste more memory while they are at it. So use a loop.