On Mon, 29 Dec 2003 10:26:40 +0800, Regent <> wrote:
> Hi, friends,
>
> Although I read several books before posting this, I still don't know
> how to declare a scalar in "common.pl" and use it directly in
> "script.pl":
Typically require inserts the contents of the required script at the point
of the require statement. However, I noticed that if I used "my $root",
it only seemed to be in scope in the required script, and was
uninitialized in main script.
> common.pl
>
> $root = "/root";
>
>
> script.pl
>
> require "common.pl"; # this line works
> print "$root"; # Global symbol "$root" requires explicit package name
>
> PS: I habitually use the -wT switch
>
> Regent
>
If I just used -w switch (and put a newline in print "$root\n"

,
I got:
Name "main::root" used only once: possible typo at ./mytest line 3.
/root
Inserting a use vars line got rid of the warning:
use vars ('$root');
require "common.pl";
print "$root\n"
If I used -wT, "." (current dir) was apparently excluded from @INC, so I
had to use a full path to common.pl (same output).
Tested in perl v5.6.1 built for i586-linux and v5.8.0 built for
i586-linux-thread-multi
--
David Efflandt - All spam ignored
http://www.de-srv.com/
PS: All mail referencing [1-9]63\.(com|net) is automatically dropped due
to excessive uncontrolled spam.