Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: 'do' read file

by scorpio17 (Monsignor)
on Dec 14, 2011 at 15:10 UTC ( #943565=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: 'do' read file
Select or Download Code
Re^2: 'do' read file
by jdporter (Canon) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://943565]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-25 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls