On Mon, 2009-08-10 at 16:13 -0400, Chas. Owens wrote:
> On Mon, Aug 10, 2009 at 16:07, Martin Spinassi<martins.li...@gmail.com> wrote:
> snip
> > It's working I don't have any issues with that :), but I'd like to know
> > something...can I make it work with "use strict"?
> >
> > Using your example would say:
> > Global symbol "$home_directory" requires explicit package name at
> > test.pl
> >
> > That appears even if "require" if over "use strict".
> snip
> 
> The problem here is that the our statement is inside of the lexical
> scope of the require.  You need to add
> 
>      our ($home_directory, $other_variable, $etc); #preferred method
> 
> or
> 
>     use vars qw/$home_directory $other_variable $etc/; #needed for
> Perl versions older than 5.6
> 
> to your code to tell the current scope those variables exist.  Another
> option you be to use the fully qualified names:
> 
>     print "$main::home_directory\n";
> 
> but that defeats the purpose of strict, so don't do that.
> 
> -- 
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.


Chas, 

The problem with that, is that one variable is added/removed from the
global config, then it should be changed at the script.

I don't know if this can do the trick, what do you think?



sub get_variables {
        open GLOBAL_CFG, "<", "./global.cfg"
           or die "Can't open global.cfg";
        while (<GLOBAL_CFG>) {
                chomp;
                if (m/^our/) {
                        [ and here, with some voodoo magic or something,
add that variable to current script ]
                }
        }
}


Cheers

Martin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to