I like the idea of using 'do', but I have what's probably a basic mis-understanding on my part.
Under use strict;, the 'do' executes what's in my configuration file, but I don't understand what happens to my scope. When I'm back in the calling file, I can't see the variable set in the config file. I tried 'package main;' at the top of my config, and it didn't do the trick.
######### calling script
#!/usr/bin/perl
use strict;
my $x;
my $file = 'my.conf';
unless (my $return = do $file) {
warn "couldn't parse $file: $@" if $@;
warn "couldn't do $file: $!" unless defined $return;
warn "couldn't run $file" unless $return;
}
print "\$x is $x\n";
########## config script (my.conf)
package main;
$x = 'abcdef';
42;
Where am I going wrong here? |