Well, I couldn't figure out how to make it TAINT safe. Taint complains pretty much any time you try to execute code you are importing from somewhere else (at least, that's my understanding).
What you should be doing is eval'ing the configuration file. Below, I read in the config.pl file into a scalar, eval it, and pop the results into the $conf hash reference.
#!/usr/bin/perl -w
use strict;
my $config_file=(""); # declare this way to prevent warnings
open(RE,"config.pl") || die("cannot open config.txt");
while(my $line=<RE>){
$config_file .= $line;
}
close(RE);
my $conf = eval($config_file); # you can look at $@ after
#this to see if eval had any errors!
print $conf->{'var1'}, "\n";
print $conf->{'var2'}, "\n";
If you have a LOT of configuration information, you might want to look at something like XML::Simple, which will allow you to create a clean* looking configuration file and use it in your script pretty easily.
* XML is a two-edged sword. It CAN be clean, but you can make it look ugly if you try :)
-oakbox
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.