in reply to Config file
This is a rather old thread but I stumbled across it looking for ideas for a config file format so I thought I would update it for future journeymen. For my config files I have settled on JSON, which I guess was not around when this thread was hewn from stone tablets. To make it easier for humans I have used relaxed (allow comments and terminal commas) and pretty options for when I output them.
use strict; use warnings; use JSON; use Data::Dumper; # Get a JSON object to handle our config file and data stores my $json = JSON->new->relaxed->pretty; # Read configuration my $cfg; # open my $config, '<', $conf_file or die "Can not read $conf_file: $! +\n"; local $/; $cfg = $json->decode (<DATA>); close $config; print Dumper $cfg; __DATA__ # Here is our config # There are many like it but this one is ours { ##################################################### # # # Data Base connections strings and active option # # # ##################################################### "DB_Connections" : { "foo" : { "conx" : [ "dbi:Oracle:FOO.world", "foo_user", "foo_pswd" ], "active" : 1 }, "bar" : { "conx" : [ "dbi:DB2:bar", "bar_user", "bar_pass", ], "active" : 0 } }, "hosts" : ( "host1" : ["readme", "andme"], "host2" : ["readthis", "that", "and another"], # comma allowed b +y relaxed ) }
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Config file
by scott8035 (Novice) on Oct 30, 2014 at 22:25 UTC | |
by kschwab (Vicar) on Oct 30, 2014 at 22:39 UTC | |
|
Re^2: Config file
by scott8035 (Novice) on Oct 30, 2014 at 22:49 UTC |