in reply to 'Required' config file produces error if last entry sets variable to zero?

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.
  • Comment on Re: 'Required' config file produces error if last entry sets variable to zero?
  • Download Code