I've been touched by the signs of spring, and trying to reduce a 1400-character program into a quine while it's still too cold to enjoy the great outdoors properly. Golf before golf, if you will, two diversions I almost never play. As with any change in seasons, it's time for a little lunchtime haiku.

I usually write for clarity, but sometimes a low stroke count is the goal of the game. I also tend to rely on the underscore glob most when I'm being purposely terse. What are some of your favorite perl operators and other coding techniques for reducing your handicap?

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Golf and Golf
by chip (Curate) on Apr 25, 2003 at 17:33 UTC
    My first thought is to use the for modifier, which doesn't require parens:

    $_{$_}++ or push @_, $_ for @T;

    But then I realized that a push in a loop is a grep/map:

    @_ = grep { !$_{$_}++ } @T;

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      ++@_{@T}, @_ = keys %_;

        I wasn't particularly playing golf with that snippet, but letting it fit the haiku. I'd like to see some other "golf patterns" besides this ever-popular uniq remake.

        --
        [ e d @ h a l l e y . c c ]

Re: Golf and Golf
by Aristotle (Chancellor) on Apr 26, 2003 at 03:29 UTC
    Given your goal:
    for (@T) { !$_{$_}++ and push @_, $_ }

    Makeshifts last the longest.