in reply to global variables

This is from the Llama book:

"a require happens at run time, so it occurs too late to serve as a declaration in the file invoking the require."

If you want the variables in inc.conf to be available globally in your program you will need to "use inc.conf" instead of "require inc.conf". The reason for this is that "use" is done at compile time.

hope this helps,
davidj

update:please disregard this post. I misunderstood the question, so my reply is incorrect. And please do not flog to too badly :)

davidj

Replies are listed 'Best First'.
Re: Re: global variables
by rsiedl (Friar) on May 31, 2004 at 14:37 UTC
    So the code can just be:
    use 'inc.conf';
    ?? Or do i need to include a use lib, because the above isnt working for me.
    I get the error:
    syntax error at global_vars.pl line 5, near "use 'inc.conf'"

    Cheers,
    Reagen

      no, it will work allright if you just change the   my $var = "blah";   to   our $var = "blah";   in   inc.conf.

      Cheers, Sören

        so like this??
        #!/usr/bin/perl use strict; use warnings; use "inc.conf"; our $var; print $var , "\n"; exit;
        And the contents of inc.conf...
        #!/usr/bin/perl use strict; use warnings; our $var = "blah"; 1;
        Because I still get a syntax error. Forgive me if I am a bit dense :)