I'm developing a Perl CGI admin script that allows a user to edit a configuration file. The config file is along the lines of:

$base='/home/foo';<BR> $logdir="$base/logs";<BR> $admindir="$base/logs";<BR>

etc. Obviously there are a lot more entries in the real config file.

At present, I'm in two minds as to how to handle editing of the file via a form.

1.) I can just do a 'require config'; and then use the values of the various variables set in the file, eg: $admindir. The only problem with this approach is if someone changes $base, then they will need to manually change all the other variablesas their values will be expanded.

2.) Change the format of the config file and read it in by splitting the variable name and value, eg:

while (<CONFIG>) { next if (/^#/); ($var,$value) = split(/=/); $value =~ s/[\$,",',;]//g; $configvar{$var}=$value; }

Obviously approach one is much simplier, but flawed (for my purposes) and method two seems very messy.

I suspect I need to look at options 3, 4 and beyond. Opinions welcomed.


In reply to Editing configuration file with a CGI Perl script by Tintin

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.