in reply to Re: Collapsing a string to unique characters
in thread Collapsing a string to unique characters

Depending on platform and Perl version:
Unix, pre 5.10: 42 -nle'@_=();@_[unpack"C*",$_]=/./g;print@_' Windows, pre 5.10: 40 -nle@_=();@_[unpack'C*',$_]=/./g;print@_ Unix, 5.10+: 40: -nlE'@_=();@_[unpack"C*",$_]=/./g;say@_' Windows, 5.10+: 38: -nlE@_=();@_[unpack'C*',$_]=/./g;say@_

Replies are listed 'Best First'.
Re^3: Collapsing a string to unique characters
by Corion (Patriarch) on Jan 09, 2009 at 14:55 UTC

    38, resp. 36 when using say instead of print

    -nle@_[unpack'C*',$_]=/./g;@_=!print@_

    Update:And 36 resp. 34:

    -nle@_[ord]=$_,for/(.)/g;@_=!print@_

    And if you're using the -E+say, you can shave off one more by leaving off the -l, at 33 strokes:

    -nE@_[ord]=$_,for/(.)/g;@_=!say@_

    Update2: And incorporating BrowserUk and JavaFan's ideas:

    # 34 strokes on Windows, and also Unix if your shell doesn't treat "!" + special -nE@_[map+ord,/./g]=/./g;@_=!say@_
Re^3: Collapsing a string to unique characters
by BrowserUk (Patriarch) on Jan 09, 2009 at 15:10 UTC

    Minus 1 on all:

    Windows, pre 5.10: 39 -nlelocal@_[map+ord,/./g]=/./g;print@_

Re^3: Collapsing a string to unique characters
by JavaFan (Canon) on Jan 09, 2009 at 15:04 UTC
    You can leave off the -l. You don't need it for the output, as you're using say. And you don't need it for the chomp, as /./ doesn't match the newline.