[stop top-posting]
chatiman said:
Well, english is not my native language. I understand it a bit so excuse me
if I misunderstand the following words from perldoc -f do :
""do FILENAME" cannot see lexicals in the enclosing scopre; "eval STRING"
does.
Which I translate (that's probably wrong) as :
- When a file evaluated with "do" sets a variable, you cannot see this
variable from the file that called "do"
........
You do misunderstand. What this means is that if you have
file1:
my $var1 = 'hello world';
do 'file2';
print $var1;
file2:
$var1 = 'foo bar';
then the code in file2 will not be able to access $var1 from $file1. If
you are using constants, which are subs, this will not affect you; if
you want variables to pass between files they should be package globals
('our' variables) rather than file lexicals ('my' variables), viz.:
file1:
do 'file2';
print $var;
file2:
our $var = 'hello world';
Note that even when using eval `cat file`, lexicals cannot pass out from
the included file to the including file, that is
file1:
eval `< file2`; # no need for useless-use-of-cat
print $var;
file2:
my $var = 'hello world';
will *not* print 'hello world'.
Using a module to hold the config information is better again, though,
as it allows you more control over which bits of config information you
import into your namespace at a given time.
Ben