in reply to the #include business
In test2.pl, $x is a lexical variable. That means it's only visible within a scope. In this case, since it's not in a block, its scope is the file itself. It will only be visible in nested scopes, never other files.
The easiest way to get this code to work is to use the vars pragma to declare $x as a global variable:
# test1.pl use strict; BEGIN { require 'test2.pl' }; print $x; # test2.pl use strict; use vars '$x'; $x = "this is it\n";
If you're doing something much more complicated, you're better off making a real Perl module and either exporting the variable or making some sort of accessor. The perlmod manpage has some good information.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: the #include business
by Anonymous Monk on Aug 23, 2003 at 08:21 UTC | |
by chromatic (Archbishop) on Aug 23, 2003 at 16:35 UTC | |
by esh (Pilgrim) on Aug 23, 2003 at 16:43 UTC | |
by Anonymous Monk on Aug 24, 2003 at 00:14 UTC |