laziness, impatience, and hubris | |
PerlMonks |
Re: Nonrepeating characters in an REby kcott (Archbishop) |
on Aug 16, 2022 at 02:50 UTC ( [id://11146152]=note: print w/replies, xml ) | Need Help?? |
G'day BernieC, I considered a solution using List::Util::uniqstr(). Unfortunately, your OP is somewhat ambiguous: you first say 'the *template* that says "these letters should be distinct"'; then you say 'my "template" might look like this: "abcdefa"' (where, with two 'a's, the letters are not distinct). I've provided two solutions; hopefully, one of them does what you want. [Caveat: uniqstr first appeared in List::Util v1.45; the first stable Perl version with that version of List::Util is v5.26; if you have an older version of Perl, you can get a newer version of List::Util from CPAN.] Solution 1 (pm_11146148_uniq_str_chars.pl):
Output:
Solution 2 (pm_11146148_uniq_str_chars_2.pl):
Output:
— Ken
In Section
Seekers of Perl Wisdom
|
|