Foo Ji-Haw wrote:
Well, the two files in question are not huge. They each have one
class. What's the difference between require-ing them later, and
use-ing them later? Why is it more difficult to require them?
I don't think it's more difficult to call a require(), use() helps in
the bigger scheme of things, like determining the scope of your
variables and methods,
Well, each of these two files has exactly one package, which is a
class. So, doesn't the package already determine the scope?
and making sure you package similar functions together.
I can't do any better than putting one class in a file.
use() also makes sure at compile time that the libraries are
available, whereas require() only checks at runtime.
That gets tricky. Because I don't know how, at compile time, to tell
use() where the libraries are. I've looked through the perlmod
documentation, and it doesn't seem to address this issue. I looked in
the Camel Book, and it talks about 'use lib'. But what's the default?
What I need to do is put in the search path the parent directory of the
one containing the main script being executed. Right now I have about a
dozen lines of code to figure that out when the script starts, which
itself uses the File::Spec module. I guess I can put all that code in a
BEGIN block, so it can run at compile time.
But in Perl, files are compiled just before they are run. It's not like
C, where there is a separate compilation step. So again, I don't see
the advantage to checking for the location of the module at compile time.
There's more to the difference between the two, and you may want to
read up the documentation for the details. It seems that best
practices go strongly with use(), and a lot of add-on support are
based on that style of development.
I will say that this is not a Perl-thing, but rather a good general
software development mindset.
Thanks, but this does seem like a Perl-thing. No other language
distinguishes between 'package-in-a-file' and 'module'.
I would say ASP, but ASP does not have a concept of a module...
In my previous email, I was assuming that you simply split all the
functions in into 2 files without using packages, and merging them
with a require(). If you are already using packages, then go for use().
In most of my scripts, I am not currently defining packages. Just in
the two that represent classes. I may convert them all to packages, if
I can be convinced this is useful. But if I put every function in a
file into a package, only to export it again, so it can be imported in
other files, what's the difference?
--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs