in reply to Re: Can't import constants in multiple namespaces
in thread Can't import constants in multiple namespaces

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.

Replies are listed 'Best First'.
Re^3: Can't import constants in multiple namespaces
by xdg (Monsignor) on Mar 28, 2006 at 12:26 UTC

    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.