Think about Loose Coupling | |
PerlMonks |
Re: eval not behaving like I expected... why?by jdporter (Paladin) |
on Mar 14, 2006 at 12:28 UTC ( [id://536549]=note: print w/replies, xml ) | Need Help?? |
Other folks have helped you figure out your perl/syntax issues, but I think there's a more fundamental issue + solution. If you're going to have your config file be executable perl code that sets some variables, at least one of the following conditions should hold:
In the first case, you can declare the variables with my in the calling code; that solves the problems you were having. In the second case, you can write your config variables like so:
Of course, that means that the variables are global, rather than lexicalized to the scope of the caller. To get a little more fancy with that approach, you could insert a dynamically decided namespace into the assignments before eval'ing:
But if you really want to go the lexical route, my personal inclination would be to store all the config variables in a single anymous hash: then just eval the file as a whole:
If you're trying to keep it simple for the sake of some non-programmers who'll have to be maintaining these config files, I respectfully suggest that you abandon the eval'able code approach altogether, and use one of the solutions already created to address this concern. Please take a look at a short list of config file modules.
We're building the house of the future together.
In Section
Seekers of Perl Wisdom
|
|