On Wednesday, June 29, 2005 3:10 AM, Sisyphus [SMTP:[EMAIL PROTECTED] 
wrote:
>
> "Perl in a Nutshell" is quite correct here, I think. If the module does not
> have a package name (which is rarely the case) then $var, $::var, and
> $main::var are all the same thing.
>
> D:\pscrpt>type trial.pm
>
> sub double_it { return $var * 2}
> 1;
>
> D:\pscrpt>type try.pl
>
> use warnings;
> use trial;
>
> $var = 17;
> $var++;
> $z = double_it();
> print $z, "\n";
>
> D:\pscrpt>perl try.pl
> 36
>
> D:\pscrpt>
>
> I think it's only if trial.pm had a package name (as it normally would) that
> 'double_it' would have to be coded as either:
>
> sub double_it { return $::var * 2}
>
> or:
>
> sub double_it { return $main::var * 2}
>
Rob, you get credit for a neat example and for an easy solution that may fit 
(obvious to you, but I never considered it)-- extend main's namespace over 
several files.  The reason $var is recognized in double_it() is that trial.pm 
is still in main's namespace when trial.pm's subroutine is compiled.  This 
means that "use trial" in try.pl just looked in the current directory, found a 
file called trial.pm, assumed it was a module, and went forward with the 
compilation, not caring whether trial.pm had a package declaration or not. 
 There was nothing to import since trial.pm didn't export anything.

But, according to Nutshell, trial.pm isn't a module.  Note what Nutshell says 
under Modules (p. 160): "A module is a package defined in a file whose name is 
the same as the package."  Now note what Nutshell says about packages under 
Namespaces and Packages (p. 160): "Each package starts with a package 
declaration.  The package call takes one argument, the name of the package..." 
So, according to Nutshell, a module must start with a package declaration that 
includes the name of the package.

(Therefore Nutshell still has a problem: $var isn't the same as $::var and 
$main::var if the symbol table changes due to a package declaration, which must 
be present according to their definition.)
>
> Your reference to "#define statements" and "constants" makes me wonder
> whether you might want to make use of the constant pragma (see perldoc
> constant), but since I can't quite get a picture of the precise scenario, I
> can't be sure :-)
>
I'll look at this very carefully, not just for this case, but for similar 
situations.
>
> Maybe your question is perfectly clear to someone else ..... otherwise you
> might have to provide a simple little demo module and script to illustrate
> the problem.

In fact my explanation wasn't clear to anyone, and I apologize. Please see my 
recent response to Bill Luebkert for a detailed elucidation.

Your comments have been very helpful, and I am very appreciative.
Regards, Neil
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to