Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: 'do' read file

by scorpio17 (Abbot)
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.

Replies are listed 'Best First'.
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?
[robby_dobby]: As in, it's-too-fancy- that-it-will-be- messy-to-handle
[choroba]: bit vectors as keys?
[robby_dobby]: Hmm, I keep falling asleep at my desk, while maintaining an active appearance. Am I getting old?
[robby_dobby]: Every time I fall asleep, there's a small guy in the dreams, shouting "Whoo!" and it jolts me awake. :/
[Lady_Aleena]: robby_dobby, at least you aren't driving. I seem to always be driving somewhere in my dreams and end up at a weird house.
[robby_dobby]: LA: That's there. But this is work and it's the same thing as falling asleep driving :-)
[Lady_Aleena]: I love the dream where I was at a huge house and decided to go swimming in the pool, but then the tour group showed up.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-05-29 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?