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

Nope, wouldn't get that error message if I left it out. I call as follows.

use Modules::ScriptUpdate;

  • Comment on Re^2: Help using self-made but very simple Module

Replies are listed 'Best First'.
Re^3: Help using self-made but very simple Module
by almut (Canon) on Oct 12, 2009 at 14:57 UTC
    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.

Re^3: Help using self-made but very simple Module
by syphilis (Archbishop) on Oct 12, 2009 at 15:01 UTC
    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
Re^3: Help using self-made but very simple Module
by toolic (Bishop) on Oct 12, 2009 at 14:56 UTC
    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.