Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked


by eyepopslikeamosquito (Chancellor)
on Aug 18, 2007 at 12:07 UTC ( #633470=note: print w/replies, xml ) Need Help??

in reply to ACA JAPH

Without understanding what your code does, I whittled 100 strokes off its length by performing some routine golfic shortenings:

@z=(sub{$c=pop;$x{$"}=$C{$"}=$";$x{$_}or$x{$C{$k}=$_}=$k=chr ord(A)+($a+++$c)%26for pop=~/./g,a..z},sub{$h=pop;$r.=$$h{$_}for pop=~/./g;$r});$z[0]->(thequickbrownfoxjumpsoverthelazydogs,10); print$z[1]->('ZOCK FWUKLMT BMTE LFQR',\%C).$/
Fits in a 4-line sig now. :-)

Update: whittled a further 10 strokes.

Replies are listed 'Best First'.
by goibhniu (Hermit) on Aug 18, 2007 at 15:46 UTC

    Wonderful. Is there a "routine golf shortenings" node?

    I humbly seek wisdom.

      <shameless plug>
      There's a number of tips and techniques listed in Perl Golf 101 as well as in the comments to that node.
      </shameless plug>

      s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

        Wow, that's a nice node that I wasn't previously aware of. The basic shortenings I made were:

        • all variable names one char in length
        • eliminate variables where you can
        • removed quotes from strings (e.g. "FRED" -> FRED)
        • $x=1;$y=1 -> $x=$y=1
        • shift -> pop in subs
        • removed return in subs
        • split // -> /./g
        • for {...} -> ... for
        • if {...} -> ... or ...
        • ' ' -> $"
        These all seem to be mentioned in Perl Golf 101, except perhaps the last one. BTW, I've added Perl Golf 101 to the list of references in The Lighter Side of Perl Culture (Part IV): Golf.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://633470]
[Eily]: marto I clearly don't have the thread knowledge to understand the importance of that example
[choroba]: the related discussion on Hacker news is interesting
[choroba]: not so many Perl haters so far

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2017-07-26 14:14 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (396 votes). Check out past polls.