Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How to remove duplicate characters in a string in place

by duelafn (Vicar)
on Feb 20, 2016 at 17:55 UTC ( #1155721=note: print w/replies, xml ) Need Help??


in reply to How to remove duplicate characters in a string in place

Still executes in a loop, but gets all instances of each letter each time (thus avoids the even/odd issue you have).

use 5.010; my $str = "abcdefghiaabccdjklm"; my $substr; $substr = "" while $str =~ s/(.)(?:(.*?)\1(?{ $substr .= $^N }))+/$sub +str/; say $str;

Good Day,
    Dean

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1155721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-03-04 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (107 votes). Check out past polls.

    Notices?