in reply to Can't import constants in multiple namespaces

You should add
use MyMod;
to the Mymod/db.pm file, right after the package declaration. Thill will call the import() method of MyMod which will export the right subroutine(s) to the MyMod::db package.

Replies are listed 'Best First'.
Re^2: Can't import constants in multiple namespaces
by mje (Curate) on Mar 28, 2006 at 12:16 UTC
    I tried:
    use strict; use warnings; package MyMod::db; use MyMod; sub fred { print "hello" if (MYMOD_DEFAULT); } 1;

    but now I get:

    Constant subroutine MyMod::MYMOD_DEFAULT redefined at /usr/local/lib/perl5/5.8.7/constant.pm line 103. Bareword "MYMOD_DEFAULT" not allowed while "strict subs" in use at MyMod/db.pm line 6. Compilation failed in require at MyMod.pm line 12. BEGIN failed--compilation aborted at MyMod.pm line 12.

      You need to quote MYMOD_DEFAULT for @EXPORT_OK

      @EXPORT_OK = ( 'MYMOD_DEFAULT' ); # or qw( MYMOD_DEFAULT )

      Also, when you "use" it, you'll need to ask for it, as you put it in EXPORT_OK, not EXPORT.

      use MyMod qw( MYMOD_DEFAULT );

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.