Undefined subroutine even though it appears in symbol table?

M

max.gruber

Suppose I've got a subroutine subA in PackageA which calls subB from
PackageB.

Now somehow I keep getting "Undefined subroutine &PackageB::subB
called at PackageA line n" (line number points to subA) depending on
from where I call subA.

For example, I can call subA from a subroutine in PackageC without
getting any error, but when I call subA from another subroutine in
PackageA, the error will appear. PackageA has a use statement for
PackageB and PackageB will export subB automatically. PackageC doesn't
have a use statement for PackageB.

When I dump the symbol table %:: just before the call to subB, in all
cases where the error appears, it will actually contain a reference to
subB. In all cases where the error doesn't appear, it won't contain a
reference. (WTF?)

Calling subB with its full name (PackageB::subB()) will always work,
by the way. But I'd rather understand why it won't work without the
package name.

Hope that was more or less understandable. ;)

I have absolutely no idea where to go from here. I'm utterly confused
and would appreciate any hints on how to solve this.

Regards,
Max
 
P

Paul Lalli

Suppose I've got a subroutine subA in PackageA which calls subB from
PackageB.

Now somehow I keep getting "Undefined subroutine &PackageB::subB
called at PackageA line n" (line number points to subA) depending on
from where I call subA.

For example, I can call subA from a subroutine in PackageC without
getting any error, but when I call subA from another subroutine in
PackageA, the error will appear. PackageA has a use statement for
PackageB and PackageB will export subB automatically. PackageC doesn't
have a use statement for PackageB.

When I dump the symbol table %:: just before the call to subB, in all
cases where the error appears, it will actually contain a reference to
subB. In all cases where the error doesn't appear, it won't contain a
reference. (WTF?)

Calling subB with its full name (PackageB::subB()) will always work,
by the way. But I'd rather understand why it won't work without the
package name.

Hope that was more or less understandable. ;)

Not really, no. Why not just post a short-but-complete script that
demonstrates the problem you're having, as suggested in the Posting
Guidelines.

Paul Lalli
 
M

max.gruber

Unfortunately, I've been unable to reproduce it outside of the program
where it occurs. And that would be much too large to post.

Anyways, how would you go about debugging a run-time undefined
subroutine error? What could possibly cause it?
 
P

Paul Lalli

Unfortunately, I've been unable to reproduce it outside of the program
where it occurs. And that would be much too large to post.

This is non sensical. Take your existing program. Remove everything
not directly related to the bug. Post what's left.
Anyways, how would you go about debugging a run-time undefined
subroutine error? What could possibly cause it?

Programmer error.

Paul Lalli
 
G

Guest

Suppose I've got a subroutine subA in PackageA which calls subB from
PackageB.

Now somehow I keep getting "Undefined subroutine &PackageB::subB
called at PackageA line n" (line number points to subA) depending on
from where I call subA.
[...]
When I dump the symbol table %:: just before the call to subB,

That's the wrong symbol table to dump. You would need to dump the symbol
table for the current package: %PackageA::
in all
cases where the error appears, it will actually contain a reference to
subB. In all cases where the error doesn't appear, it won't contain a
reference. (WTF?)
[...]

Most probably your "use" statement is in the wrong place. Evidently, you
"use" PackageB while the current package scope is main, so PackageB's
functions are imported into the main package instead of PackageA.

This will import names into the main package:

#!/usr/bin/perl
use PackageB;

package PackageA;
.... some stuff ...

This will import names into PackageA:

#!/usr/bin/perl
package PackageA;
use PackageB;
.... some stuff ...


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top