in reply to Problems with using strict
That will create a global variable %main::country which can be referred to from other scopes (such as a different file) by name. Using my in module.pm won't work, because it scopes the variable locally to that file, ie it will vanish as soon as execution returns from the file. Another alternative I'd prefer in this case is to create a hashref in the included file:use vars qw(%country);
and then use do on it:+{ af => 'afghanistan', ao => 'angola', ar => 'argentina', at => 'austria', au => 'australia', bd => 'bangladesh', be => 'belgium', bg => 'bulgaria', };
Now a reference to the constructed hash is stored in $country:my $country = do "countries.pl"; die "Error loading country data: $@\n" if $@;
print "$country->{af}\n";
(Note that do does an implicit eval.)
Update: that's my $country = do ..; of course.
Makeshifts last the longest.
|
|---|