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:

$ 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/ $
The lexicals $foo and $baz mask the global versions, but global $bar is seen.

Changing the lexical my line to use vars qw/$foo $bar $baz/;, and useing strict and warnings, we get

$ ./cfg /foodir/ /bardir/ /baz/dir/ $
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.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Config file
by perlcapt (Pilgrim) on Jun 17, 2006 at 15:32 UTC
    The modern way of globalizing the variables that are set in the do "config" is to declare them with our rather than use vars.
    perlcapt
    -ben