in reply to Config file
That format looks like legal perl, so it can be as simple as: do 'config.file';.
As it is, that won't survive strict, so you need to declare your variables. They will need to be in the symbol table because lexicals have file scope, and do FILE's cannot see lexicals from the caller.
An example:
The lexicals $foo and $baz mask the global versions, but global $bar is seen.$ cat >cfg.pl $foo='/foodir/'; $bar='/bardir/'; $baz='/baz/dir/'; $ cat >cfg #!/usr/bin/perl my ($foo,$baz); do 'cfg.pl'; print $foo,$/; print $bar,$/; print $baz,$/; $ chmod 755 cfg $ ./cfg /bardir/ $
Changing the lexical my line to use vars qw/$foo $bar $baz/;, and useing strict and warnings, we get
It's tempting to make the config file more independent by declaring its variables within it, but forcing users to know the names will prevent nasty namespace collisions.$ ./cfg /foodir/ /bardir/ /baz/dir/ $
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Config file
by perlcapt (Pilgrim) on Jun 17, 2006 at 15:32 UTC |