in reply to Re^3: Counting unique elements in an array
in thread Counting unique elements in an array

That is jumping through some hoops to avoid void.
Well, yeah. I was posting them in sort of a humor/brainteaser vein rather than as a serious solution to a problem that is (as has been pointed out)
  1. probably homework, and
  2. a FAQ

Incidentally, here's a method that benches about 9% faster than for_loop:

sub new_guy { my %sums; ++$_ for @sums{@array}; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^5: Counting unique elements in an array
by Random_Walk (Prior) on Feb 08, 2005 at 20:28 UTC

    cunning indeed, significantly faster.

    Benchmark: running for_loop, map_void, new_guy, nonvoid_1, nonvoid_2 f +or at least 3 CPU seconds... for_loop: 4 wallclock secs ( 3.19 usr + 0.00 sys = 3.19 CPU) @ 15 +55.17/s (n=4961) map_void: 3 wallclock secs ( 3.29 usr + 0.00 sys = 3.29 CPU) @ 11 +30.40/s (n=3719) new_guy: 3 wallclock secs ( 3.07 usr + 0.00 sys = 3.07 CPU) @ 19 +67.10/s (n=6039) nonvoid_1: 3 wallclock secs ( 3.15 usr + 0.00 sys = 3.15 CPU) @ 33 +9.37/s (n=1069) nonvoid_2: 3 wallclock secs ( 3.15 usr + 0.01 sys = 3.16 CPU) @ 13 +9.87/s (n=442)

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!