Think about Loose Coupling | |
PerlMonks |
Re: Sort list by position of items in another listby drclaw (Acolyte) |
on Feb 19, 2022 at 04:16 UTC ( [id://11141485]=note: print w/replies, xml ) | Need Help?? |
Hi,
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/ )? 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:
Hope it might be of use or interest to your application Ruben
In Section
Seekers of Perl Wisdom
|
|