Can I not declare variables within a 'required' file when running under 'strict'??
You are being bitten by the unrelated lexical scope of required files.
Declare the variables you are using in the config file as our variables, and
declare them in the main file with our (or better, use vars) also, prior to the require "config.pl"
statement. Since you are using them in two files, shared between them, introducing them to
both parties using them is not only polite but sensible, and sometimes required, since our variables are lexically scoped, as are my variables - but our variables can be package globals.
Let's read the documentation of our again:
our associates a simple name with a package variable in the current package for use within the current scope. When use strict 'vars' is in effect, our lets you use declared global variables without qualifying them with package names, within the lexical scope of the our declaration. In this way our differs from use vars , which is package scoped.Unlike my, which both allocates storage for a variable and associates a simple name with that storage for use within the current scope, our associates a simple name with a package variable in the current package, for use within the current scope. In other words, our has the same scoping rules as my, but does not necessarily create a variable.
I read that as meaning that if you don't declare our variables used elsewhere (in a required file) beforehand, they do not necessarily relate to package globals created in the calling scope after the require - when the scope of the required file is no longer in effect. At least, there's nothing in the docs that would guarantee such a behaviour. Update - see Why is 'our' good?.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: Variable declaration in 'required' file doesn't work under 'strict'?
by shmem
in thread Variable declaration in 'required' file doesn't work under 'strict'?
by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |