in reply to Re: Fastest way to "pick without replacement"
in thread Fastest way to "pick without replacement"

Using a slice in the delete call will sidestep the for-loop. The map can also be replaced with a slice.

hash_slice => sub { my %ha; @ha{0..$#numbers} = @numbers; delete @ha{@indices}; my @output = @ha{sort keys %ha}; join("\0", @output) eq join("\0", @expect) or die if TEST; },

Replies are listed 'Best First'.
Re^3: Fastest way to "pick without replacement"
by swl (Prior) on Nov 21, 2020 at 03:06 UTC

    The sort should also be numeric.

    hash_slice => sub { my %ha; @ha{0..$#numbers} = @numbers; delete @ha{@indices}; my @output = @ha{sort {$a <=> $b} keys %ha}; join("\0", @output) eq join("\0", @expect) or die if TEST; },

    Update: Although I now see Choroba has already done that in 11123952.

Re^3: Fastest way to "pick without replacement"
by bliako (Abbot) on Nov 20, 2020 at 23:53 UTC

    coolz!