Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: How to Order an Array's Elements to Match Another Array's Element Order

by swl (Curate)
on Sep 17, 2019 at 08:46 UTC ( #11106283=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11106283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2019-12-09 05:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?