on 1/25/02 10:41 AM, [EMAIL PROTECTED] purportedly said:

> How can I export $foo to 'cat' ?
> The following doesn't work. $foo in cat is undefined.
> I tried "local $foo" in dog. It asks for a package name, and that doesn't work
> either in cat.
> 
> #!perl -w
> # this is dog
> use strict;
> my $foo = 10;
> require 'cat'; # a perl script
> __END__
> 
> #!perl -w
> # this is cat
> use strict;
> my $foo = $::foo;
> print defined($foo) ? $foo: 'undefined',"\n";
> __END__
> 

The "require" statement always loads into package "main" (the default
package). That is, the "require" statement is tantamount to copying and
pasting the contents of the require'd script into the main script. Unless
you declare a different package in cat, the $foo variable is still in scope.
Perhaps the circular declaration in:
     my $foo = $::foo;
is confusing Perl. Remove this line and try again.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"

Reply via email to