Me don't like...

The problem with what you're doing is that you can have someone write dangerous code in their config file which you'd just interpret on your merry way. It's sort of like setting up a Perl CGI script that takes input and does a system call on it.

Besides, Perl code is not exactly easy for a novice to figure out. Even if it's just <var> = <value> lines. Did they put a "$" is front of each variable? What about semicolons on the end of each line? Plus, if you used "use strict", they'd have to put "my" infront of each variable. Better to read in the config file and parse it yourself. Even if all you're doing is an eval on the line. At least you can check each line's grammar to make sure the user is only setting a variable. Something like this:

open(CONFIG, "$file") or die qq(Can't open "$file" for reading); foreach $line (<CONFIG>) { eval qq($line) or die qq("$line" is not valid code!); }
I think you're better off using Config::INI::Simple. It makes a nicer and easier to understand Config file.

In reply to Re: 'Required' config file produces error if last entry sets variable to zero? by qazwart
in thread 'Required' config file produces error if last entry sets variable to zero? by punch_card_don

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.