in reply to Sub calling sadness

Wow, lots of varied answers.

Let me distill the correct answer from the various posts.

ThatPackage::blah is not defined as a sub when the call to ok is compiled, because you coded require instead of use. I don't know if that is something else you should look into, or an artifact of your testing framework.

I'm not sure, but I think use strict 'refs' would spot the problem. Why don't you have use strict at the top of your file?

So, the contents of $bar is taken as a package name at run-time (think new Blah; vs. $x="Blah"; new $x;), and the white space is a problem at this time. I don't know why it spotted it at "compile time" unless it has something to do with the constant optimizer.

Anyway, change the require to use, and then it will behave as greedy arguments to a function call without parens, since it knows that is a function.

—John
writing from 西安 (Xi'an), China

Edited 10-March re correction from ikegami (writing from 昆明 (Kunming))

Replies are listed 'Best First'.
Re^2: Sub calling sadness
by ikegami (Patriarch) on Mar 08, 2008 at 17:50 UTC

    Small correction:
    "So, the contents of $bar is taken as a method name at run-time"
    should be
    "So, the contents of $bar is taken as a class name or object reference at run-time" (ThatPackage::blah would used as the method name: <<Can't call method "ThatPackage::parse" without a package or object reference>>)

Re^2: Sub calling sadness
by nefigah (Monk) on Mar 09, 2008 at 05:45 UTC
    Awesome, it all makes sense now. This was my first time using my own functions from another file, and I wasn't sure if it was safe to use use without defining export lists and whatnot, so I just did require. In light of this I changed it to use, and it works, and revealed the problems you all have been talking about, just like you guys said. Many thanks!


    I'm a peripheral visionary... I can see into the future, but just way off to the side.