in reply to Re^2: map sentence with subtraction interpreted as with negative number
in thread map sentence with subtraction interpreted as with negative number

Well, I said I found your first case confusing, I think this one is worse, it took me far too much time to understand what you meant to do. But the main difference is that the previous example at least was a plain old syntax error, caught at compile time. This one is valid syntax:

use strict; use warnings; open my $A, '>', 'out.txt'; print $A -1 == 0 ? "A\n" : "B\n";
This makes it even trickier as it might be seen too late. And this means you can't say that you can guess that an operator is not unary when there is a scalar on its left, because perl actually allows this kind of constructs.

BTW, since the ternary operator makes your example even more confusing (I find its priority obvious but non intuitive, which means I get it right but need to think about it), it can be reduced to: print $A +1;

Edit: reduced even further from $A +1 +2 to $A +1

Replies are listed 'Best First'.
Re^4: map sentence with subtraction interpreted as with negative number
by rsFalse (Chaplain) on Dec 01, 2015 at 14:30 UTC
    Thanks.
    But it's strange:
    open my $A, '>', 'out.txt'; print $A - 1 == 0 ? "A\n" : "B\n"; # prints 'B' to STDOUT print STDERR - 1 == 0 ? "A\n" : "B\n"; # prints 'B' to STDERR
      As someone said, 'indirect objects are pretty wicked'. They're a great source of bugs. You probably shouldn't torture the Perl's parser so hard in this spot, since it's especially fragile here.