radman has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm in the process of getting more familiar with writing modules since they pretty much rule. This subject has been a mystery to me for a long time until I actually took the time to read through the O'Reilly section of "Programming Perl" on Packages, Modules and Objects. Now it seems rather easily tackled.
However, there's something I'm still confused on here. So when you 'use Module qw(LIST)' it's like saying:
BEGIN {
require Module;
Module->import(LIST);
}
That much I understand. From what I understand about the -> operator, saying Module->import(LIST) is the same as saying &{$Module{import}}(LIST) correct? I also notice that there's no '$' on the front of Module so what is this symbol? I'm totally confused on this issue.
The thing that I did in learning the magic of modules, is build a very simple module like the following:
package PerlModuleEducation1;
use strict;
use vars qw($someVar);
sub import(@) {
print "PerlModuleEducation1::import(\@) called.\n";
}
$someVar = 10;
sub someFunc($$) {
my ($s1,$s2) = @_;
print "You called PerlModuleEducation1::someFunc($s1,$s2)!\n";
}
Thus, if I use require then I can use $someVar and someFunc($$) with qualifiers. Also, if I use 'use' I can do virtually the same thing, but since the function has a prototype and use is really a BEGIN then I can use someFunc LIST. But the point being that I can use with out an error saying I have no import(LIST) function.
I originally thought that I'd have to create some anonymous hash called PerlModuleEducation1 and then put a refrence to a sub called 'import' inside it, but turns out, I can just write import as a normal function inside the .pm file and everything works fine. Why is that?
This has been R A D...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Module Education
by chipmunk (Parson) on May 18, 2001 at 22:56 UTC | |
|
Re: Perl Module Education
by arturo (Vicar) on May 18, 2001 at 22:43 UTC | |
by t'mo (Pilgrim) on May 19, 2001 at 02:50 UTC | |
by radman (Novice) on May 18, 2001 at 22:51 UTC | |
|
Re: Perl Module Education
by radman (Novice) on May 18, 2001 at 22:25 UTC |