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.

Pereant, qui ante nos nostra dixerunt!

In reply to Re: Config file by Random_Walk
in thread Config file by cajun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.