Hello,

I've got a dozen or so of modules in a directory - (ie: FOO_X.pm, FOO_Y.pm, etc..) And a some scripts (ie: A.pl, B.pl, C.pl, etc) that make use of them. The size/scope of the modules is too large to puthere (and they require access to a database to work) Creating tiny test examples work fine. I have not got a small reproducable example yet. The modules are collections of like minded routines. ie: Report.pm, Schedule.pm, Tasks.pm, Orders.pm. The scripts live in a "bin" directory, and the modules live in a "lib" directory.

For some reason, I seem to have random "undefined subroutine" problems that I cannot explain.

BEGIN SHORT DESCRIPTION: The problem is like this:

If I execute script A, which uses Module X - which then uses module Y - then Z... it works.

If I execute script B, which begins with a different module, which - uses modules just like A, andin the end - uses Y, and Module Z... it does not.

The path that script B takes causes causes Y's references to Z to fail as undefined subroutines.

The only known work around I have is to fully qualify every access to Z's functions. (ie: In the form: ModName::FuncName) I should not have to do that.

END SHORT DESCRIPTION

Longer description graphically - its like this:

A -> use FOO_ModuleX; -> use FOO_Module_Y; -> use FOO_Module_Z
By that, I mean: script A uses Module X directly. Module X uses Y, Module Y - then uses Module Z. My script does not reference Z it directly

Script B, enters the maze from a different location, somewhere along the way - something it uses Y, which uses Z... and that is the problem.

The scripts start with the same boilerplate, and look like this:

#! /usr/bin/perl use strict; use warnings; # Std Perl Modules use Carp; use File::Copy; ... actual list varies depends on script ... # Our modules. use FOO_X; ... actual list varies depends on script ... #======================= # Code begins... # A trivial example my $msg = foo_x_function( "hello" ); print "$msg\n" exit 0;

NOTE: I do not know if this matters: I do not "use *.pm" (ie: a "use" statement for every one of my modules in every one of my modules.... However but the "use" hierachy is not purely recursive, the modules are 'mutually recursive'. Huh? you ask... I am not using recursion... I'm describing the 'use Name;' relationship between *MY* modules.., like this:

A use relationship graph between my modules could be described as Spagetti.

The problem seems to be related to the 'use relationship path' or it is a namespace/scoping problem.

I've read - quite a number of things - with no luck For example:

Technical details...
================================ PERL Version: (host RH EL4 - intel) This is perl, v5.8.5 built for i386-linux-thread-multi ================================ ====================================== The style/format of my modules are like this: (From: http://perldoc.perl.org/perlmod.html example) ====================================== #! /usr/bin/perl package NameX; use strict; use warnings use NameY; use NameZ; BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); $VERSION = 1.00; @ISA = qw( Exporter ); @EXPORT = qw ( &func1 &func2 ); %EXPORT_TAGS = (); @EXPORT_OK = qw(); } sub func1 { } sub func2 { } ======================
To answer some questions I've seen asked before: Remember - it works - if I execute it via one script, but does not work if I execute it via another script.

At this point, I'm at a loss to figure this out. When I have problems like this in C code, I resort to the preprocessor output and other things like that... I don't know how to do things like that with perl. For example: Is there a means to have perl explain what it is doing During a use statement... perhaps something like this would help me:

use Works_First; TURN_ON_MAGIC_HERE; use ProblemModule; TURN_OFF_MAGIC_HERE; use OtherModules;
Thanks, --Duane.

In reply to Module Undefined Subroutines, works one way - not another by duane_ellis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.