Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Beyond Golf - reading between the tokens

by Juerd (Abbot)
on Dec 28, 2002 at 12:51 UTC ( [id://222720]=note: print w/replies, xml ) Need Help??


in reply to Beyond Golf - reading between the tokens

I think much easier would be to just:

perl -MO=Concise -e'foo' | wc -l
Example:
5;0 juerd@atlas:~$ perl -MO=Concise /usr/bin/cpanp | wc -l /usr/bin/cpanp syntax OK 260
The cpanp binary has a score of 260.

5;0 juerd@atlas:~$ perl -MO=Concise -e'$t' 2> /dev/null | wc -l 5 5;0 juerd@atlas:~$ perl -MO=Concise -e'$$t' 2> /dev/null | wc -l 6 5;0 juerd@atlas:~$ perl -MO=Concise -e'$$t[0]->{x}' 2> /dev/null | wc +-l 11 5;0 juerd@atlas:~$ perl -MO=Concise -e'$$t[0]{x}' 2> /dev/null | wc -l 11 5;0 juerd@atlas:~$ perl -MO=Concise -e'print $$t[0]{x}' 2> /dev/null | + wc -l 13

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Beyond Golf - reading between the tokens
by theorbtwo (Prior) on Dec 28, 2002 at 15:15 UTC

    I thought of that too, but it does have some problems. Eval-string is very cheap in that accounting. print 'a'.'b'; is cheaper then print 'a','b'; (the former constant-folds to print 'ab';).


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      I concur with Juerd - the costs are assesed correctly if you throw non-trivial cases into the equation. As far as eval STRING is concerned, I'm wondering if it shouldn't simply be forbidden.

      Makeshifts last the longest.

      I thought of that too, but it does have some problems. Eval-string is very cheap in that accounting. print 'a'.'b'; is cheaper then print 'a','b'; (the former constant-folds to print 'ab';).

      This is why print "a"."b"; is faster and more efficient than print "a","b";. I think it is *good* to have the former be less points.

      When not using constants, it's a different story: print "a".$_; is 9 concise-lines while print "a",$_; is 8.

      I think eval-string should be avoided anyhow, in a golf contest like this one.

      - Yes, I reinvent wheels.
      
      - Spam: Visit eurotraQ.
      

        Try playing your modified golf game with a program to produce the 100 bottles of beer song. The winner is obvious, but I maintain is more complex from a maintainance perspective than a far shorter dynamic solution.

        All forms of golf raise the question of trying to define what kind of shortness is appropriate. There is no good answer. And the more natural the answer that you try to come up with, the trickier the boundary cases become. There is no good solution.

        PS Stupid trick for regular golf. If side-effects are unspecified, then eval is often more shortly written as s//print"Some code here"/e

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://222720]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-28 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found