Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Configuration file design

by holli (Abbot)
on Jan 04, 2005 at 11:05 UTC ( #419205=note: print w/replies, xml ) Need Help??


in reply to Configuration file design

if the user is perlwise (and only then), my favourite option is to simply put the config-data as perl code in the config-file, like
"root" => "/path/to/root", "filepath" => "/path/to/files", "ftp_instances" => [ { "sourcepath" => "/source/path/on/server", "savepath" => "/save/files/here", }, { "sourcepath" => "/source/path/on/server", "savepath" => "/save/files/here", }, ]
Then you can simply read the file, do
eval "%CFG = (" . readfile("cfg") . ");";
and you´re gone.

The benefit is that you can safely bring in all kind of difficult data (newlines etc.), and you can use an idiom you are pretty much used to.

just my $ 2/100

Replies are listed 'Best First'.
Re^2: Configuration file design
by Juerd (Abbot) on Jan 04, 2005 at 16:23 UTC

    eval "%CFG = (" . readfile("cfg") . ");";

    Is there any specific reason for not using my %CFG = do 'cfg'; instead?

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      if any, then because i didn´t know it could be done that way ,-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-12-08 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?