in reply to conf file in Perl syntax
If you are new to perl probably you don't want starting installing modules...
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: conf file in Perl syntax
by afoken (Chancellor) on Jun 11, 2009 at 11:23 UTC | |
Re^2: conf file in Perl syntax
by Ravendark (Acolyte) on Jun 11, 2009 at 11:25 UTC | |
by GrandFather (Saint) on Jun 11, 2009 at 21:11 UTC | |
by Anonymous Monk on Jun 11, 2009 at 12:34 UTC |
In Section
Seekers of Perl Wisdom