in reply to Sort list by position of items in another list
How about a hash slice? No sorting required.
johngg@abouriou:~$ perl -Mstrict -Mwarnings -E 'say q{}; my @PCHR = qw{ K Q R B N P }; my $w1 = q{QRKPNB}; my %w1LU = map { $_ => $_ } split m{}, $w1; say join q{}, @w1LU{ @PCHR };' KQRBNP
I hope this is of interest.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort list by position of items in another list
by LanX (Saint) on Feb 19, 2022 at 02:28 UTC |