I have a number of strings, made up only of 64 characters: a-zA-Z0-9/+ . I need to collapse these down to just the unique characters in the string. I can do this with a one-liner, but there's got to be a better way to do this.
I've looked at regexes, and map, but I can't figure out anything really clean and fast.
Given input data like
9b/lllqtUst48MMMxwBHz+wluFguNx5h3DnyKxfxFjNazwc0X 9b/lllqtxTElC8GLsftS2RKkAxI1MfQTIuNx5h3P4eoEphA31djsn 9b/lllqtyk/lC8MMMxwwwhcTAxlhNBl1ugoluNx5h3fjxud309RVeCIY 9b/lllqtcxP8MMMxBvFfOh8lLxQTfguNx5h3LKrE0maElw 9b/lllqtdx48MMMxw6h4+mol1ugoluNx5h3AKrdGQ9OCnW 9b/lllqtf2l48MMMxDxaxxz29OAHIuNx5h3wG2TEyFqu3RdBin 9b/lllqthPElC8MMMxw78QQ0bfaPlI14TfguNx5h30beTAmP1cfA+Z 9b/lllqtryA8GL2m2s9OQrxzotuIuNx5h3MUw/45uzMeC5ww
and this one-liner:
perl -lne 'chomp; undef %h; @p=split(//,$_); foreach $k (@p) { $h{$k}= +$k; } print (sort keys(%h));' test-strings
I get these correct results:
+/034589BDFHKMNUXabcfghjlnqstuwxyz /1234589ACEGIKLMNPQRSTbdefhjklnopqstux /013589ABCIMNRTVYbcdefghjkloqtuwxy /03589BEFKLMNOPQTabcfghlmqrtuvwx +/1345689ACGKMNOQWbdghlmnoqrtuwx /234589ABDEFGHIMNORTabdfhilnqtuwxyz +/01345789ACEIMNPQTZabcefghlmqtuwx /234589ACGILMNOQUbehlmoqrstuwxyz
Any pointers are appreciated! Thanks!
Update: Got it, thanks! But the golfing has commenced...
In reply to Collapsing a string to unique characters by dwhite20899
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |