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

I was recently pondring a chunk of obfuscated code. I figured most of it out, but am still having trouble with  __ in this expression:

lc( (split // => \"aString" .. __)[1] )

Here are my questions.

Replies are listed 'Best First'.
Re: Un-obfuscate me
by chipmunk (Parson) on Dec 19, 2000 at 01:07 UTC
    __ isn't actually a special variable; it's a bareword! It's really just the string '__'.

    split operates on \"aString" .. __. As the second argument to split, the .. is actually in scalar context. That's what I can't figure out: \"aString" .. __ doesn't do anything useful in scalar context.

    In list context, "a" .. __ would return strings from 'a' to 'zz'; it stops at 'aaa' because 'aaa' is longer than '__'.

      Not true, wise chipmunk. The .. operator in scalar context 'is bistable' and is false until the first condition is met, then is true until the second condition is met and then is false. A fun toy that is better explained in perlop.

      It is far beyond my meager skills, though, to figure out what this is supposed to do. Is it typed in correctly? I cannot make this snippet output anything. <P mikfire
      mikfire

        I know that .. is a flip-flop operator in scalar context. However, note that perlop goes on to say:
        If either operand of scalar ".." is a constant expression, that operand is implicitly compared to the $. variable, the current line number.
        That's why I said that \"aString" .. __ doesn't do anything useful in scalar context. :) I should have clarified that I was referring to that expression specifically, rather than to scalar context .. in general.

        You're right! I did type it incorrectly when I first asked the question. The original is this:

        @^T = qw, 3( 2 9 6); 21_PENGUINS, and print map {(lc((split//=>\"\"=>")[$^T>1])..__)[$_]}@^ +T

        Which, of course, answers my third question: it is obvious that split is operating on \"aString".

        While I was searching for the orignial, I also found some commentary on this little proggie. In fact, it looks like somebody else had the same problem I did, the __. How does 'c' .. __ create an alphabet generator? What's going on?

      I thought the _ underscore character in code was a cached alias for the last file test, i.e.
      if (-f $file) { if (-s _ ) { ... } ... }
        Yes, that's true, a single underscore is a special filehandle for the filetest operators. But, when used in a non-filehandle context, it's just a bareword, like any other filehandle.

        ...besides, we've been discussing two underscores...