plechazunga has asked for the wisdom of the Perl Monks concerning the following question:

Something that's been frustrating me lately is that I keep getting the "Undefined subroutine" error without being able to quite figure out why. It usually happens when module A imports module B (both mods here having package names), and module B imports module C (which does NOT have an explicit package name). If I write a script that calls B directly, it'll run fine, but I get the runtime error if the script calls A (which in turn calls B). I've monkeyed around with Exporter, which hasn't helped, and I'd rather not have to give module C its own package space (because it's already in use in a lot of different scripts).

(I'm not posting any code because 1. there are a jillion lines total by now, and 2. some proprietary stuff involved.)

I can't figure out what else to do, so I turn to you professionals.

Replies are listed 'Best First'.
Re: How to debug "undefined subroutine"
by moritz (Cardinal) on Jul 31, 2011 at 19:27 UTC

    Boil the problem down to a few lines, and present it here. You seem to have a rather good understanding for when the problem occurs, so it shouldn't be too hard for you to write a short script and two (mostly empty) modules that exposes the same problem.

Re: How to debug "undefined subroutine"
by tospo (Hermit) on Aug 01, 2011 at 08:17 UTC
    You don't need to post the specific code but you could post the "header" of the script with the "use" statements and the headers of the modules involved including a mock (empty) sub. In fact, I would recommend even for your own error-finding strategy to try and re-create the problem with as little code as possible - just some mostly empty modules with subs that just print "hello" or something. If you can re-create the problem, you have an easy set-up to debug and post it here.