|
|
| Syntactic Confectionery Delight | |
| PerlMonks |
Re: Nonrepeating characters in an REby atcroft (Abbot) |
| on Aug 16, 2022 at 03:36 UTC ( [id://11146153]=note: print w/replies, xml ) | Need Help?? |
|
Interesting problem. Out of curiousity, I played around with the idea and got the following (ugly!) one-liner to work (reformatted for readability):
It can probably be cleaned up or made shorter (as I was just trying to get something working). I originally approached the idea of doing a split-sort-join on the original string to get an ordered string, testing that for duplicate characters, but after getting it working I realized the grep() was the meat of the code, and the rest could be eliminated. For anyone curious, here was my original code:
Hope that helps. Here's a shorter value for a single string:
Update: (2022-08-15) - Removed unnecessary '/g' and '/x' from the regex in the grep. Removed an errant line of text that was left while editing the response. Removed READMORE tags around first code snippet. Fixed punctuation error in response text. Added shorter code examples at end.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||