Undefined subroutine even though it appears in symbol table?

Discussion in 'Perl Misc' started by max.gruber, Jan 27, 2007.

  1. max.gruber

    max.gruber 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.

    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
    max.gruber, Jan 27, 2007
    #1
    1. Advertising

  2. max.gruber

    Paul Lalli Guest

    On Jan 27, 10:58 am, "max.gruber" <> wrote:
    > 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
    Paul Lalli, Jan 27, 2007
    #2
    1. Advertising

  3. max.gruber

    max.gruber Guest

    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?
    max.gruber, Jan 27, 2007
    #3
  4. max.gruber

    Paul Lalli Guest

    On Jan 27, 3:06 pm, "max.gruber" <> wrote:
    > 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
    Paul Lalli, Jan 27, 2007
    #4
  5. On 01/27/2007 09:58 AM, max.gruber wrote:
    > 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

    --
    Windows Vista and your freedom in conflict:
    http://techdirt.com/articles/20061019/102225.shtml
    Mumia W. (NOSPAM), Jan 28, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGh1cndpdHo=?=
    Replies:
    1
    Views:
    438
    Teemu Keiski
    Apr 10, 2004
  2. Joergen Bech
    Replies:
    2
    Views:
    3,274
    Joergen Bech
    Jul 2, 2005
  3. craig dicker
    Replies:
    9
    Views:
    650
    Juan T. Llibre
    Jul 7, 2005
  4. Replies:
    0
    Views:
    689
  5. Paul
    Replies:
    1
    Views:
    404
    Adam Maass
    Aug 14, 2003
Loading...

Share This Page