Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery


by goibhniu (Hermit)
on Aug 18, 2007 at 15:46 UTC ( #633495=note: print w/replies, xml ) Need Help??

in reply to Re: ACA JAPH
in thread ACA JAPH

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

I humbly seek wisdom.

Replies are listed 'Best First'.
by chargrill (Parson) on Aug 18, 2007 at 17:42 UTC

    <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://633495]
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy
[Lotus1]: Cosmic37 if you undef $/ in a local context to a block it won't affect the global version after the block finishes
[Lotus1]: or you can just do local $/ in a block
[erix]: cool

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-06-29 16:50 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (673 votes). Check out past polls.