Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, When I require a script and don't use strict I can import the variable, when I use strict it doesn't work. Why is this and how can I get test.pl to work using strict? Thanks and regards
#!/usr/bin/perl -w #test.pl #use strict; require "test1.pl"; print "Content-type: text/html\n\n"; print "$test";
and
#test1.pl $test = 'TEST THIS!!';

Replies are listed 'Best First'.
Re: receiving variables from another script
by GrandFather (Saint) on May 06, 2006 at 07:33 UTC

    In what fashion doesn't work? Generates an error or warning? Just doesn't do anything? Causes the CPU to overheat then explode?

    Because you don't declare $test anywhere in test.pl Perl makes it global to everything. If you use strict the strictures require $test to be declared. If you do that it becomes local. You can use strictures and require by declaring the variable with our:

    #!/usr/bin/perl -w #test.pl use strict; use warnings; require 'noname1.pl'; our $test; print $test;
    use strict; use warnings; our $test = 'This works!';

    Prints:

    This works!

    DWIM is Perl's answer to Gödel
      Thank you. I apologise for lack of clarity. I go now to find a fire extinguisher for CPU, and possibly an hard hat...