in reply to Re: Sub calling sadness
in thread Sub calling sadness

This will call ThatPackage::blah with first argument of $baz using object dispatching

"Object dispatching?" No, ThatPackage::blah $foo is not an indirect method call if ThatPackage::blah has been declared as a sub. It's a simple function call.

If sub blah didn't exist in ThatPackage, then it would be an indirect method call, but $baz would be used as the class name, not as an argument.

Replies are listed 'Best First'.
Re^3: Sub calling sadness
by pc88mxer (Vicar) on Mar 08, 2008 at 07:27 UTC
    My point is simply that when you use the syntax ThatPackage::blah $foo, perl treats it as a method invocation and expects $foo to look like an 'object' (either a blessed reference or a package name), and this is why the OP is getting the error.

      My point was that's not true except in the unusual case where the function is not known when the statement is compiled.

      What I didn't catch is that it turns out that's the case here. Because require was used instead of use, blah didn't exist when the ok statement was compiled, therefore Perl assumed the OP was trying to do an indirect method call. The solution is to change the require to a use (or wrap it with a BEGIN) or to use parentheses.

      Omitting parens in Perl is dangerous. Prepare to encounter odd problems once in a while when Perl incorrectly guess what you want to do. One specific rule is that parens (or "&") are REQUIRED when the function isn't declared before it's used.