note
drclaw
Hi,
<p>What about inverting the search? You already know the order of the characters. Match them as many times as possible against the input string as a regex with each character as an alternative (ie input "QRKPNB" becomes /Q|R|K|P|N|B/ )?</p>
<p>These couple of lines generate the regex based on the input and match the sorted list against it. The joined matches become the (sorted) output string:</p>
<code>
my $PCHR="KQRBNP";
my $w1="QRKPNB";
my $w2=join "", $PCHR=~/@{[join "|",split "",$w1]}/g;
print "$w1 -> $w2\n";
</code>
<p>Hope it might be of use or interest to your application</p>
Ruben
11141469
11141469