in reply to Syntax and Temporary Variables

This is a problem with indirect object syntax mentioned in perlobj, quote (update: this quote is grabbed from bleadperl docs):

... 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:
move $obj->{FIELD}; # probably wrong! move $ary[$i]; # probably wrong!
Those actually parse as the very surprising:
$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
    Thanks, I understand it now. Using braces fixes it while still maintaining the prefix notation of in.

    Now if it was imported, then calling it as a function with one argument should work just fine, right? It calls the same function. But when I specified it in the import list, it still complained that &main::in did not exist. That is strange.

    —John