----- Original Message ----- 
From: "L. Neil Johnson" <[EMAIL PROTECTED]>
To: "'Sisyphus'" <[EMAIL PROTECTED]>
Cc: "'Win32-Users'" <perl-win32-users@listserv.ActiveState.com>
Sent: Thursday, June 30, 2005 4:22 PM
Subject: RE: Importing Identifiers from Main::


> 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.
>

Yep - I looked at the initial quote you provided from Nutshell which was "If
the package name is null, the main package is assumed", and read that as
meaning "If the package name of the module is null, the main package is
assumed". The only way I could make sense of that was if you had a pm file
that didn't declare a package name. But you're right - in view of the other
text you've quoted it's obvious that my inclusion of "of the module" was way
off. In fact their definition of a module as "a package defined in a file
whose name is the same as the package" is probably *everybody's* definition
.... so it's hard to come up with an excuse for taking the approach I did
(but I'll continue to work on one :-)

> (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.)

Yes, a package name must be present in a module, but not necessarily present
in a script. And if the script doesn't declare a package name, then $var,
$::var, and $main::var are all one and the same (within that script).
Perhaps that's what they're getting at ??

I don't think they would be meaning that a "$var" within a module could ever
be the same as "$main::var" or "$::var", because clearly that "$var" has
been declared within a package and must therefore be "$package_name::var".

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to