http://www.perlmonks.org?node_id=943565


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 general, I think it's considered "bad practice" to put executable code into a config file.

    So don't think of it as a config file. Think of it as a module for setting some variables.

    (That said, I have nothing against Config::Auto. They should call it Config::Awesome.:-)

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.