in reply to Order of operations

The Perl print statement allows an optional file handle right after "print", like print $handle stuff....
You are confusing print.

In your code:

print "(4-1) + 2+3 * (2*2) = ", (4-1) + 2+3 * (2*2), "\n\n"; #script 1 + answer 17 print (4-1) + 2+3 * (2*2);#script 2 does not work
add a dummy null string at the beginning to script 2:
print "",(4-1) + 2+3 * (2*2);
This makes it clear that the first arg is not a file handle.

Replies are listed 'Best First'.
Re^2: Order of operations
by haukex (Archbishop) on Nov 16, 2017 at 07:42 UTC
    The Perl print statement allows an optional file handle right after "print" ... This makes it clear that the first arg is not a file handle.

    Sorry but that's not the reason print gets confused, it's the parens. The optional file handle is independent of those:

    $ perl -wMstrict -le 'print ( STDOUT "42") + 1' print (...) interpreted as function at -e line 1. Useless use of addition (+) in void context at -e line 1. 42 $ perl -wMstrict -le 'print ({*STDOUT} "42") + 1' print (...) interpreted as function at -e line 1. Useless use of addition (+) in void context at -e line 1. 42
      Fine, you are correct. print is confused for a different and more technically correct reason than what I said. However, my suggestion "un-confuses" print.
        However, my suggestion "un-confuses" print.

        You are correct ;-)