I was fascinated by the perl minigolf site and I was reading solutions in casual order. I was particularly attracted by the winning solution to The Archeologists' Dilemma. The solution is the following:
-l 2**++$_=~/^@ARGV/.$'>2 .$&?print:do$0
but the problem is that it doesn't work. But wait! I'm using perl v.5.8.6, so I looked into the generic perl golf rules at the site - perl 5.8.0 is the reference. I happen to have it installed, but no luck again.

While writing this node as a SoPW, the solution slapped my face at once - do you see it?

This was my analysis. The solution can be rearranged as
-l 2**++$_=~/^@ARGV/ . $' > 2 .$& ?print :do$0
The greater-than test is supposed to work not before the iteration in which $_ is equal to the solution, in which case the print branch is taken; otherwise the other branch is taken triggering a recursion.

The real not-working part is the following:

-l 2**++$_=~/^@ARGV/ . $'
It is supposed to perform the match and to evaluate to the last value for $', which is initially undefined. The problem is that the dot operator, which merges $' to the previous expression, simply has an higher precedence over the named unary operator -l, so instead of
(-l 2**++$_=~/^@ARGV/) . $'
it evaluates like
-l (2**++$_=~/^@ARGV/ . $')
which is assured to be undef if you work in an empty directory, and won't ever evaluate to $'.

But how could this solution win? Impossible - in this way. But I then realised: it was a typo!!! I quickly turned the dot into a comma:

-l 2**++$_=~/^@ARGV/,$'>2 .$&?print:do$0
and all worked fine! Congratulations, tybalt89!

Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

Don't fool yourself.

Replies are listed 'Best First'.
Re: Minigolf solution not working - can you see why?
by japhy (Canon) on Jun 16, 2005 at 20:21 UTC
    Note: the -l here is not the unary filetest -l operator, but rather the -l switch to perl.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
      CRASH! Death of a card-castle.

      In effect, during a scooter trip to go back home, I was just thinking that the -l was not needed. So... why is it there? Now I know. Thanks japhy :)

      Next time I'll ask in the CB without cluttering the Monastery.

      Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

      Don't fool yourself.