in reply to Configuration files via require or do and my, local.

When you use my in the file being required, you are declaring the variables within the file scope. When you leave the file, they are no longer accessable. I would recommend using 'our' instead of 'my'.

  • Comment on Re: Configuration files via require or do and my, local.

Replies are listed 'Best First'.
Re: Re: Configuration files via require or do and my, local.
by Anonymous Monk on Mar 24, 2002 at 17:39 UTC
    I found the answer: "my" is space scoped (context NOT carried outside the file) "local" is run-time scoped (context into other files beneath this scope.) However, you can use "vars" in conjunction with "use strict" to decl global vars. Make sure to go back and remove the "my" in front of the variables. Thanks, Daniel

      This:

      use vars qw( $foo ); $foo = 1;

      And this:

      our $foo = 1;

      Do the exact same thing. Though, "our" may not be available to you in Perl 5.005.

        They don't do the same thing when you put curly braces around them. Be careful with your word "same" there.

        -- Randal L. Schwartz, Perl hacker


        update: Since I managed to confuse a few people in the CB just now, let me add this:
        our is a lexical-scoped aliasing of package variable (in the current package), while use vars is a package-scoped relaxation of the normal use strict rules. You cannot universally swap one for the other: they have overlapping uses and meanings, but also distinct uses and meanings.