in reply to 'do' read file
In general, I think it's considered "bad practice" to put executable code into a config file. Try doing something like this instead:
#!/usr/bin/perl use strict; use Config::Auto; use Data::Dumper; my $config = Config::Auto::parse("1.spec", format => "equal"); print Dumper($config), "\n";
And change your config file ("1.spec") to something like this:
NAME = Philip AGE = 21
When you run this code, you should get this output:
$VAR1 = { 'NAME' => 'Philip', 'AGE' => '21' };
In other words, $config is a hash ref pointing to the data read from the config file.
Config::Auto is very powerful, and can handle much more complicated situations. Read more about it on CPAN.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: 'do' read file
by jdporter (Paladin) on Dec 14, 2011 at 16:01 UTC |
In Section
Seekers of Perl Wisdom