in reply to Re: Re: Re:^2 Golf: string complement
in thread Golf: string complement

Not quite. A list grep in a scalar context return the size of the list.

sub invert { #23456789012345678901234567890 grep/[^\Q@_\E]/,map{chr}1..255 }; $inverted = invert( 'Just Another Perl Hacker!' ); print $inverted; 237

237 + 18 (unique characters in the string) = 255.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Re: Re: Re:^2 Golf: string complement
by davido (Cardinal) on May 16, 2004 at 03:51 UTC
    I actually already did toy with the idea of interpolating the output of grep into a string, but it turned out to fail to gain any ground; it works, but it's no shorter, plus to get identical output you would have to also set $" to '' (empty string), which takes additional keystrokes..

    My 37 keystroke method:

    sub invert { #234567890123456789012345678901234567 join'',grep/[^\Q@_\E]/,map{chr}1..255 }

    And now without join, but with double-quotish interpolation:

    sub invert { #234567890123456789012345678901234567 "@{[grep/[^\Q@_\E]/,map{chr}1..255]}" }

    Dave