wrote:
> Paul Lalli wrote:
> > wrote:
> > I don't have my copy of the Cookbook on me, but I have to believe
> > you're misinterpreting what it's telling you.
>
>
> You're right. Reading further, I see it shows how to use the lines of
> code you indicated. But that's a lot of stuff, and how did I get this
> far without needing it? I looked at my earlier code and noticed this:
> My key module -- I even call it Reusables.pm -- doesn't have a package
> statement! So going back to the example in my posting, I removed the
> package statement in ATrial.pm, and the program worked without the
> explicit reference "ATrial::". Apparently Perl is giving me some
> undocumented latitude in external referencing, and I can only wonder
> where the boundaries are.
Any piece of code that does not have an explicit package statement in
effect is in package main::. Therefore, when you removed the package
ATrial; statement, that code in ATrial.pm became part of the main::
package as well. When you call a subroutine without a fully-qualified
name (ie, without the package label), it is taken to mean "the current
package". Since both your main file and ATrial.pm are in the same
package, the code executes without errors. You would have seen the
same result if you'd added 'package ATrial;' to your main file, rather
than removed it from ATrial.pm
When you 'use Atrial;', you're really doing two distinct things:
require 'Atrial.pm';
Atrial->import();
The first line simply loads the code in Atrial.pm. The second line
attempt to import from the Atrial class. Nothing about the first line
says that Atrial.pm has to contain a package named Atrial::. And as
for the second line, if no such class exists, the import() call is
silently ignored (I believe via a call to the "empty" core level
import() function, but I could be wrong on that).
Check out
perldoc -f use
perldoc -f require
for more information
Paul Lalli