CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: General Discussions: Tutorial/Article Suggestions for The Learning Cent:
Modules and References

 



fashimpaur
User

Sep 6, 2000, 2:16 PM

Post #1 of 2 (26194 views)
Modules and References Can't Post

How about some topics on creating modules?

I spent serious time learning to write them and the documentation required is sparse at best. Even the good Perl books all seem to stop a day late and a dollar short when it comes to the nuances of modules and the tricks to make them more powerful. How about articles on Modules - General, Inheritance (Perl Style), Exporting Methods and tags, Importing Methods and tags, etc.

Also, I have struggled to find out what the heck the 'SUPER::' thing is that some of the core modules use. How about touching on those types of things?

Also, boy, do I remember the trouble I had when something like this happened to me...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


Some.pm

package Some;

sub someMethod {
...
return \%someHash;
}
1;
</pre><HR></BLOCKQUOTE>
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


someScript.pl

use Some;

$someScriptVar = Some::someMethod();
print "Result: $someScriptVar\n";
exit;

</pre><HR></BLOCKQUOTE>
Then when I ran someScript.pl, I got...
Result: HASH(0x0FF34800)

I've since learned some of the neat things
about references, but there are probably a
lot of new people out there struggle with the
concepts. Yeah ... read perlreftut POD ...
sure. I think I'll start with the Septugiant (? spelled wrong I think) to learn Greek. Smile


[This message has been edited by fashimpaur (edited 09-06-2000).]

[This message has been edited by fashimpaur (edited 09-06-2000).]


japhy
Enthusiast / Moderator

Sep 6, 2000, 2:56 PM

Post #2 of 2 (26194 views)
Re: Modules and References [In reply to] Can't Post

I'll answer as much as I can here. I don't have time to write a full article on it, since I have other things in the works.

First, as far as exporting functions and variables, have a GOOD READ through the Exporter.pm docs. They explain how to use the Exporter module, and the @EXPORT, @EXPORT_OK, and %EXPORT_TAGS variables.

Inheritance is far easier in Perl than, say, C++. None of this private/protected/public nonsense:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


package BaseClass;
sub new; # you do have to actually DEFINE these functions...
sub this;
sub that;

package SubClass;
@ISA = qw( BaseClass );
sub new;
sub this;

package main;
$a = SubClass->new;
$a->that();
# SubClass does not provide a 'that' method
# but SubClass inherits from BaseClass, which
# does have a 'that' method
# the equivalent call is similar to
# BaseClass::that($a);
</pre><HR></BLOCKQUOTE>

A class can inherit from many other classes. The order of base-class searching is depth-first. That is, first check $ISA[0]'s methods. If not there, if that class has an @ISA tree, go through THAT, and so on. If no match is found, go to $ISA[1].

Hmm. That's all for now. You might see an article from me in a couple of months.

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives