Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by dave_the_m (Monsignor)
on Sep 17, 2019 at 10:40 UTC ( #11106287=note: print w/replies, xml ) Need Help??


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

Create a hash to map name to index and use that to sort.
my %index; @index{@array} = 0..$#array; my @result = sort { $index{$a} <=> $index{$b} } @subset;

Dave.

  • Comment on Re: How to Order an Array's Elements to Match Another Array's Element Order
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2019-11-14 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (80 votes). Check out past polls.

    Notices?