in reply to Re: Re: Operator Precedence (unary nagation and exponentiation)
in thread Operator Precedence (unary negation and exponentiation)

Use -w!
$ perl -wle 'print (-2)**2' print (...) interpreted as function at -e line 1. Useless use of exponentiation (**) in void context at -e line 1. -2

Just like any other function, if the function name is followed by a left paren, it's taken as the start of the argument list. print (-2)**2 is parsed as (print (-2)) ** 2. This is even documented. From perldoc print:

Also be careful not to follow the print keyword with a left parenthesis unless you want the corresponding right parenthesis to termi- nate the arguments to the print--interpose a "+" or put parentheses around all the arguments.

Abigail

Replies are listed 'Best First'.
Re: Re: Operator Precedence (unary nagation and exponentiation)
by Arien (Pilgrim) on Jan 14, 2003 at 11:39 UTC

    Good catch, I should have used -w... sigh

    Arien mumbles something about how anybody can forget to put in switches now and then. ( -f ;-)

    — Arien