in reply to Sort list by position of items in another list
I'm not sure if it looks less awkward ;)my $i = 0; # use constant PCHR => split //, 'KQRBNP'; # my %pchr = map { $_ => $i++ } PCHR; use constant PCHR => 'KQRBNP'; my $w1 = 'QRKPNB'; my $w2 = join '', map $_->[1], sort { $a->[0] <=> $b->[0] } map [ ( index PCHR, $_ ), $_ ], split //, $w1; print "$w1 -> $w2\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort list by position of items in another list
by gflohr (Acolyte) on Feb 18, 2022 at 18:22 UTC |