On Dec 19, 2003, at 1:16 PM, christopher j bottaro wrote:
i'm reading "Programming Perl" and i'm on the chapter about packages. it says
that packages and modules are very similar and that novices can think of
packages, modules, and classes as the same thing, but i wanna know exactly
what the differences between packages and modules are (i'm a c++ programmer,
i know what classes are).
p0: the obligatory perldoc perl there are some tutorials it will list, also go with perldoc perlmod, et al for that side.
{ you really will want to pick up RS's Learning Perl Objects, References and Modules }
Now that we have the Orthodoxy out of the way.
p1: in My Most Humbled Opinion.
a module is an externally referencable file, normally suffixed with *.pm that contains some 'code stuff'
a package is a specific name space.
A modules SHOULD contain at least one package line in it, it may contain more than one of them, defining more than one package name space. our classic illustration is
use Foo::Bar;
will tell the compiler to look for a 'module' that manages the package Foo::Bar - it will normally be installed in the file system in the form Foo/Bar.pm and is required to use the Methods/Functions in Foo::Bar name space.
So as to screw things up, it is POSSIBLE to create a package space inside a script, a la
#!/usr/bin/perl -w use strict; # note - no use Foo::Bar here since we define the # package namespace locally in this file we do not go external
my $foo = new Foo::Bar; BEGIN { # so the perl runtime compiler compiles my package foist package Foo::Bar; use 5.006; use strict; use warnings; #our @ISA = qw(PARENT_CLASS); our $VERSION = '0.01'; #--------------------------------- # Our Stock Constructor sub new { my $type = shift; my $class = ref($type) || $type; my $self = {}; bless $self, $class; } # end of our simple new #--------------------------------- # so that AUTOLOAD finds one here sub DESTROY {} # # your methods here # 1; # so that the 'use Foo::Bar' # will know we are happy } # end begin
and it will act like your expected 'class model' from C++ land, but without all of the technical stuff about whether or not you want to have a compiler that does pre-compiled headers, yada-yada-yada.
Likewise one can have a perl module, a file that is foo.pm and IT can have more than one package name space in it. But I tend to avoid that most of the time unless I have a really good reason to disagree with myself.
Now a Perl Module Does NOT have to be an OO approach, as one can get into exporting the 'functions' - cf Exporter but I rather doubt you will want to go that way.
also, what is a good perl vbulletin forum (vbulletin plz, i'm a little baby
and dislike other kinds of web forums...=)?
ok, I bite, what is a vbulletin, I'm an OldGuy and use to do this with uucp doing usenet news groups, and do it by email now.
you might scope out the monestary. <http://www.perlmonks.com/> or read the docs online <http://www.perldoc.com/>
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>