Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11106287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found