OnionKnight has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to make a configuration file which another perl script reads. Looking at other peoples scripts they all use require() and wrap it in a BEGIN block which works fine but not in this case since I am using $dir in the filename and $dir is dependent on %ENV which isn't known at compile time I guess. What I get is a "Undefined subroutine" error. Something I don't understand, why would it even matter if it's in a BEGIN block? The require()'s come before the usage of those constants anyway so it shouldn't matter?
Example:
#config.pl use strict; eval 'use constant SOMETHING => "asdf"' unless(defined(\&SOMETHING)); 1; #test.pl use strict; use File::Basename; my $dir = dirname($ENV{"SCRIPT_FILENAME"})."/"; require("${dir}config.pl"); print &SOMETHING;
|
|---|