note
rsFalse
Ye, it looks awkward or longer, because Perl have no such array index function or sort by array index function in its core.<br><br>
Perl has some string index functions ([docs://index] and [docs://rindex]). In your example they may be used instead of hash, e.g. using Schwartzian transform:<br>
<code>
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";
</code>
I'm not sure if it looks less awkward ;)
11141469
11141469