Consider this:
Note how chomp and chop are the only ones that get parsed the way they do.perl -MO=Deparse,-p print $x= "hi"; chomp $x= "hi"; chop $x= "hi"; sprintf $x= "hi"; printf $x= "hi"; reverse $x= "hi"; join $x= "hi"; unlink $x= "hi"; die $x= "hi"; warn $x= "hi"; __END__ print(($x = 'hi')); (chomp($x) = 'hi'); (chop($x) = 'hi'); sprintf(($x = 'hi')); printf(($x = 'hi')); reverse(($x = 'hi')); join(($x = 'hi')); unlink(($x = 'hi')); die(($x = 'hi')); warn(($x = 'hi'));
Quoting bits of perlman:perlop:
If any list operator (print(), etc.) or any unary operator (chdir(), etc.) is followed by a left parenthesis as the next token, the operator and arguments within parentheses are taken to be of highest precedence, just like a normal function call.left terms and list operators (leftward) [...] right = += -= *= etc. [...] nonassoc list operators (rightward) [...] =head2 Terms and List Operators (Leftward) [...]On the right side of a list operator, it has very low precedence,[...] =head2 List Operators (Rightward)
So that means that list operators w/o parens around their arguments should bind less tightly than assignment operators. This is the case for all of the list operators I used in my sample code except for chop and chomp. I can't find anything special about those two core functions that would explain their special treatment.
This is made worse by the fact that chomp( @x )= whatever; doesn't generate an error like all of these do:
(I've already reported this last bug to p5p.) such that chomp my @input= <STDIN>; does nothing useful but reports no errors nor warnings (well, it declares @input and leaves it empty and then reads one line from STDIN and throws it away, most of which isn't useful). - tye (but my friends call me "Tye")chop( $x )= whatever; chop( @x )= whatever; chomp( $x )= whatever;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: chop/chomp bind too tightly
by japhy (Canon) on Nov 14, 2001 at 23:48 UTC | |
by tye (Sage) on Nov 15, 2001 at 00:04 UTC | |
|
Re: chop/chomp bind too tightly
by Anonymous Monk on Nov 15, 2001 at 00:19 UTC | |
by tye (Sage) on Nov 15, 2001 at 02:06 UTC | |
|
Re: chop/chomp bind too tightly
by Zaxo (Archbishop) on Nov 15, 2001 at 02:52 UTC |