in reply to Print not printing

This is invoking the print FILEHANDLE LIST syntax

If you use warnings;, you would see

print() on unopened filehandle 10

     "There are only two truly infinite things. The universe and stupidity, and I'm not too sure about the universe"- Albert Einstein

Replies are listed 'Best First'.
Re^2: Print not printing
by tlm (Prior) on Jun 24, 2005 at 05:57 UTC

    Yes, but the mystery remains: why isn't this syntax invoked in the expression print $a + $b, which should be syntactically equivalent to print $a +$b.

    the lowliest monk

      It seems this is one of those rare occasions where white space does matter. The parser has to take a guess at what +$b is supposed to be and guesses that a unary + is used. Bug or feature? Depends on how you look at it, I guess :)

      Paul

        It's a beature! No, a fug!

      As already said, there is room for ambiguity in this syntax. So although whitespace should not be relevant, it is used to disambiguate things.

      It really is a Perl DWIM thing.

      By putting a space before the + and not behind it, you seem to hint to Perl that the + is now a unary plus and automagically the $a now becomes a filehandle.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law