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

Re: Sort list by position of items in another list

by Fletch (Bishop)
on Feb 18, 2022 at 16:22 UTC ( [id://11141470]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use 5.010;
    use List::MoreUtils qw( sort_by );
    ...
    my $w1 = 'QRKPNB';
    my $w2 = join '', sort_by { $pchr{$_} } split( //, $w1 );
    say "$w1 -> $w2";
    
  2. or download this
    my %pchr = do { my $i; map { $_ => $i++ } qw( K Q R B N P ) };
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-03-29 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found