http://www.perlmonks.org?node_id=438980


in reply to Replaying Santa Claus Golf Apocalypse with Pugs/Perl6

After updating to the most current Pugs and incorporating all the ideas above, here is my final strike on the Santa Claus Perl6/Pugs Golf Apocalypse:
--- head.p6 --------------------------------------------- print*(=open@ARGS[0])[0..9] --- tail.p6 --------------------------------------------- my@l= =open@ARGS[0]; print@l[(@l>9??@l-10::0)...] --- rev.p6 --------------------------------------------- print reverse=open@ARGS[0] --- mid.p6 --------------------------------------------- my@l= =open@ARGS[0]; print@l[int((@l-1)/2)..int(@l/2)] --- wc.p6 --------------------------------------------- say*(split"",int(7e10+ +*(=open@ARGS[0])))[1..11]
It is all but nice but is is actually only 203 strokes...:-)

rg0now

Replies are listed 'Best First'.
Re^2: Replaying Santa Claus Golf Apocalypse with Pugs/Perl6
by audreyt (Hermit) on Mar 12, 2005 at 20:15 UTC
    Hey, why =open@ARGV[0] instead of =<> again? That will save 10 strokes per hole, bringing it to a more respectable 153...
      This is because we are ran by
      my $cmd = "pugs $scr $intmp";
      which means that we are getting the name of the file to be read as the first command line argument. But, based on my (granted, limited) understanding, =<> would read from the standard input. Am I completely missing something here again?

      rg0now

        =<> is supposed work the same as magical <> in Perl 5. To explicitly read from standard input would require =$*IN instead.
Re^2: Replaying Santa Claus Golf Apocalypse with Pugs/Perl6
by pdcawley (Hermit) on Mar 29, 2005 at 07:47 UTC
    Can open take a block yet?
    open@ARGS[0]{print..11}
    or is open ... {...} a figment of my imagination?
      Quite a strange syntax, I think. And apparently, Pugs thinks so too, because it croaks badly when I try to run your version.

      Even though, the fact that neither Pugs nor me seem to recognize this syntax, this does not mean to any extent that it is illegal. If you can recall where you met it, I can definitely make a todo_test out of it for autrijus to implement...

      rg0now

        It's a rubyish thing: Open this and then call the block for every line of the resulting file handle, closing the file at the end. I'd not be surprised if it's a hopeful figment of my imagination.