in reply to scope with multiple files
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.
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.#!/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";
* XML is a two-edged sword. It CAN be clean, but you can make it look ugly if you try :)
-oakbox
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: scope with multiple files
by IOrdy (Friar) on May 22, 2002 at 15:40 UTC |