You can't read lexical variables from an external file and see them in your file. With strict or without. That's one of the scope restrictions dictated by my.
Anyway, you can't escape when use strict is in effect, but you shouldn't do without. Consider two alternative solutions:
1: Create a module and export the variables you need from there. See perldoc perlmod and perldoc Exporter
2: Use OOP. A quick-and-dirty solution could be to create a bare bones class with some attributes you can pull out via class or object methods, but it's not that elegant :-). I'll write some untested crap below here, but you should really look for something better that fits your needs
package MyProgramConfiguration ;
use strict ;
use warnings ;
# Take this as a starting point,
# *NOT* as an example, *PLEASE*!!!
my %config = (
color => 'yellow',
beverage => 'chinotto',
food => 'pizza',
driver => 'Schumacher',
) ;
my gimmeconf {
# I don't care how you called me (class or object method)
return %config ;
}
And your prog could do:
use strict ; # don't leave it out
use MyProgramConfiguration ;
my %c = MyProgramConfiguration->gimmeconf() ;
In case I didn't say that, I'll say it again: don't take this as production code!!! Read it, understand how it works and create your solution from scratch. You have been warned. Also, you should read about lexical variables and how they work.
Ciao! --bronto
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->made($love) ;
}
|