in reply to Syntax and Temporary Variables
... what if there are no arguments? In that case, Perl must guess what you want. Even worse, it must make that guess at compile time. Usually Perl gets it right, but when it doesn't you get a function call compiled as a method, or vice versa....
.... the indirect object is limited to a name, a scalar variable, or a block, because it would have to do too much lookahead otherwise, just like any other postfix dereference in the language. (These are the same quirky rules as are used for the filehandle slot in functions like "print" and "printf".) This can lead to horribly confusing precedence problems, as in these next two lines:Those actually parse as the very surprising:move $obj->{FIELD}; # probably wrong! move $ary[$i]; # probably wrong!$obj->move->{FIELD}; # Well, lookee here $ary->move([$i]); # Didn't expect this one, eh?
The docs go on to explain that move {$ary[$i]}, etc. could have been used to gain the proper effect, but still they advise strongly to use -> exclusively because of these problems.
update (2): added "etc."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Syntax and Temporary Variables
by John M. Dlugosz (Monsignor) on Jul 21, 2001 at 01:09 UTC |