There is a poor man's solution for evaluating configfiles as scripts with do
this works with your example:
our $config; do './conf.pl' or die "Can't read config $!"; print $config->{host_1};
or even more error proved described in the docs with
# read in config files: system first, then user for $file ("/share/prog/defaults.rc", "$ENV{HOME}/.someprogrc") { unless ($return = do $file) { warn "couldn't parse $file: $@" if $@; warn "couldn't do $file: $!" unless defined $return; warn "couldn't run $file" unless $return; } }
BE AWARE: do searches the @INC directories, so better use a path to avoid problems...
Cheers Rolf
UPDATE: As I wrote the config-file is evaluated as script not parsed as data, so be aware of necessities of securing this code! If it's just a one way script, and you have full control it's ok. If you mean to write a full scale program for others, better use a config-module.
In reply to Re: conf file in Perl syntax
by LanX
in thread conf file in Perl syntax
by Ravendark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |