in reply to Help using self-made but very simple Module

Did you forget to use ScriptUpdate; in your TLEQUERY.pl script?

Replies are listed 'Best First'.
Re^2: Help using self-made but very simple Module
by kdmurphy001 (Sexton) on Oct 12, 2009 at 14:39 UTC
    Nope, wouldn't get that error message if I left it out. I call as follows.

    use Modules::ScriptUpdate;

      use Modules::ScriptUpdate;

      If you load it like this, your package name should be Modules::ScriptUpdate accordingly, or else Exporter will alias main::script_stats() to Modules::ScriptUpdate::script_stats(), not ScriptUpdate::script_stats(), where it would reside in your case with a package name of ScriptUpdate...

      In more detail, the reason is that use Modules::ScriptUpdate; implcitly calls Modules::ScriptUpdate->import(), which in turn (via inheritance) calls Exporter->import() with the first parameter being "Modules::ScriptUpdate".  This then is the namespace used by Exporter, not what you specified in the module source with package. For this reason - when you use Exporter - package name and filename/path of the module have to match.

      use Modules::ScriptUpdate;

      The usual thing to do is to have the module name match the package name - ie in ScriptUpdate.pm it would be usual to declare package Modules::ScriptUpdate; instead of package ScriptUpdate; (as you have done).

      Cheers,
      Rob
      Yes, you would get that message if you forgot use:
      use strict; use warnings; script_stats(); __END__ Undefined subroutine &main::script_stats called at TLEQUERY.pl at line + 3.