Hello, Monks!

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.