Ovid has asked for the wisdom of the Perl Monks concerning the following question:

Yuck, this is humiliating. I can't seem to figure this out. In the latest Obfuscated Perl Contest, the following is listed:
( $ ,, $ ")=("a".."z")[0,-1];print "sh", $ ","m";;";;"
What's even more humiliating is that I can't understand the explanation:
You're indexing twice into the alphabet, and then printing three strings separated by the now-meaningful $,
I get the first part about indexing, but I'm not sure exactly what the 'a' is being assigned to. I've used the debugger and it will print 'z' for $ ", but I can't find where 'a' is going, much less how these are being passed to the print function. And what's up with the the last part? $, is the output list separator, but so what? My brain's been turned inside out and hung up to dry (a line from Cryptonomicon, if anyone cares).

Replies are listed 'Best First'.
Re: Obfuscated Perl Question
by chromatic (Archbishop) on Aug 10, 2000 at 21:02 UTC
    $, gets a, $" gets z.

    'sh' is printed, then $, (normally blank, but now a), then $", then $ again, then m. You can drop everything after the first semicolon after the print statement, and apparently the whitespace isn't significant with the magic variables. Interesting.

    Remember, print with commas in it uses list context.

Re: Obfuscated Perl Question
by jlistf (Monk) on Aug 10, 2000 at 21:02 UTC
    the 'a' is being assigned to $, so we print "sh" then $, then $ " then $, then m. or: sh, a, z, a, m.

    jeff

    p.s. cryptonomicon is a very good book.
(Ovid)RE: Obfuscated Perl Question
by Ovid (Cardinal) on Aug 10, 2000 at 21:07 UTC
    D'oh! I knew it had to be something simple. The debugger apparently didn't want to print out the list separator when I entered p $,. Of course, now that I do it again, it works fine. Go figure :( That's going to bug the heck out of me how I missed that.

    Aack, phht!

(jeffa) Re: Obfuscated Perl Question
by jeffa (Bishop) on Aug 10, 2000 at 21:14 UTC
    I tried this one with the warning option on.
    Can someone explain what is causing perl to warn about
    Useless use of a constant in void context . . .?

    Thanks

      The last few characters were ;";;".
      The first semicolon ended the previous statement, making the last line just the string ";;" used in void context...