gomez18 has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a fairly large project and decided to split things up nicely into packages. One of these packages is called dslDefine. It's in /usr/local/lib/perl5/5.6.0/dslDefine.pm. I use exporter to export out some variables (lexically scoped) such as usernames and such that should be visible everywhere. I have all the variables exported thusly:

our @EXPORT = qw($VAR1 $VAR2...);

This library is used in dslRB (/usr/local/lib/perl5/5.6.0/dslRB.pm) via a standard use statement. The problem I'm having is that the variables defined in dslDefine, while apparently exported (No complaints from "use strict"), yield an undefined variable error whenever I try to use them.

Does anyone have any idea how to resolve this? If there's a vastly superior way to go about this, please let me know.

An 8 bit man in a 32 bit world.

Replies are listed 'Best First'.
Re: Variable scoping in packages
by arturo (Vicar) on Oct 10, 2001 at 00:25 UTC

    Here's a forehead-smacker (made this mistake myself):

    arturo>perldoc -f our our EXPR An "our" declares the listed variables to be valid globals within the enclosing block, file, or "eval". That is, it has the same scoping rules as a "my" declaration, but does not create a local variable.

    HTH

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
      Perfect. That got the job done. That is indeed a real head smacker. Thanks a million.

      An 8 bit man in a 32 bit world.

Re: Variable scoping in packages
by John M. Dlugosz (Monsignor) on Oct 10, 2001 at 00:22 UTC
    You can't export lecically scoped ("my") variables. You're exporting a package variable by the same name.

      Actually you can, you just can't use Exporter.pm to do it. (:

              - tye (ya know)
        You're not going to get away with just a teaser, you know.

Re: Variable scoping in packages
by perrin (Chancellor) on Oct 10, 2001 at 00:20 UTC
    I think you want to use globals, not lexicals for this. You don't really need to export them either. The exporter just saves some typing.