edbewald has asked for the wisdom of the Perl Monks concerning the following question:
I am not a new perl programmer and have learned most of what I know about PROGRAMMING IN GENERAL from this website. And though that may give me an edge, I am far from eloquent. Now I have a question.
I inherited a rather convoluted script from a former employee. He, unfortunately, did not believe in using warnings nor strict. He 'requires' a file that contains only 'constant' variables. My question is what is the easiest way to bring constants defined in one script into another.?
constants.pl:
$TRUE = 1; $FALSE = 0;
Main script:
require "constants.pl"; foreach $num ( 1...5 ) { if ($num < 3) { print $TRUE,"\n"; } else { print $FALSE,"\n"; } }
Desired output:
1 1 0 0 0
There are over 300 constants in the constants.pl file so this is just an example. I have tried making constants.pl into a package, using 'our' (not really sure when or if to use this), and 'use constant'. Searches on this site and the web have given me suggestions, but so far I can't make the main program import the 'constant' variables into my main script.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Importing vars from one script to another
by space_monk (Chaplain) on Dec 11, 2012 at 20:37 UTC | |
Re: Importing vars from one script to another
by BillKSmith (Monsignor) on Dec 11, 2012 at 23:03 UTC | |
by edbewald (Beadle) on Dec 11, 2012 at 23:52 UTC | |
by rovf (Priest) on Dec 12, 2012 at 09:51 UTC | |
Re: Importing vars from one script to another
by ww (Archbishop) on Dec 11, 2012 at 23:33 UTC | |
Re: Importing vars from one script to another
by Anonymous Monk on Dec 11, 2012 at 20:55 UTC |