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.

In reply to Minigolf solution not working - can you see why? by polettix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.