in reply to Re: How to Order an Array's Elements to Match Another Array's Element Order
in thread How to Order an Array's Elements to Match Another Array's Element Order

Just a data point, but an alternative way to generate the hash is to use slice assignment. It is faster than using map if %index_map is to be generated many times, e.g. across data sets.

my %index_map; @index{@array} = (0..$#array);

Replies are listed 'Best First'.
Re^3: How to Order an Array's Elements to Match Another Array's Element Order
by Eily (Monsignor) on Sep 17, 2019 at 09:40 UTC

    Good point :). Although I like it more because it short than because it is fast (I basically treat speed considerations as insignificant until proven otherwise :) )

      Yes, it's more concise. It does also need to be called a large number of times to be meaningfully faster.