in reply to Un-obfuscate me

__ 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 '__'.

Replies are listed 'Best First'.
Re: Re: Un-obfuscate me
by mikfire (Deacon) on Dec 19, 2000 at 01:43 UTC
    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.

        Wouldn't \"aString" .. __ essentially be the same as 1 .. 1 in this context? If so, then the string "1E0" would be returned when the first line of data is read ("1" for first line counted, "E0" for last line counted.)

      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?

        Okay, now we're back to .. in a list context. This makes a lot more sense!

        Looking in perlop, I find that 'c' .. '__' will generate all the strings from 'c' to 'zz', because:

        If the final value specified is not in the sequence that the magical increment would produce, the sequence goes until the next value would be longer than the final value specified.
        The next string after 'zz' is 'aaa'; length('aaa') is greater than length('__'), so the sequence ends.

        The map is used to generate this list of strings and select a certain string five times; those five strings are printed to produce the author's name.

Re: Re: Un-obfuscate me
by Jonathan (Curate) on Dec 19, 2000 at 18:01 UTC
    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...