There's some great documentation on this.  Check out 'perldoc perltoot' on
your local command line or
http://www.perldoc.com/perl5.6.1/pod/perltoot.html if you're into that "web"
thing.

Here's my hello world class

package Hello; #A package declaration starts a class

#A method to create a new instance of my class
sub new {
        my ($class, $message) = @_;

        my %hash;
        $hash{message} = $message;

        return bless  \%hash, $class;  #An object is a blessed reference.
}

#Some silly method
sub sayit {
        my $self = shift;
        print "Hello $self->{message}\n";
}

package main;  #now switch to the main package
# if you had the Hello class in a separate file called Hello.pm you would
need to 'use Hello;' here

#instantiate my class
my $hello = new Hello ("World");

#invoke my method
$hello->sayit();


Of course, this example is lame, but simple.  Take a look at the above
documentation for more explanations and details.  If you like the book thing
check out Damian Conway's "Object Oriented Perl" for more than you ever
wanted to know.

Peter C.


-----Original Message-----
From: Connie Chan [mailto:[EMAIL PROTECTED]]
Sent: Sunday, December 30, 2001 9:56 AM
To: [EMAIL PROTECTED]
Subject: How to create an object with perl ?


I only know how to use simple hash to carry pairs of data, however,
Would anybody could tell how can I create a new object in perl ?
and how can I call a property's value ? Any very simple live example ?

Have a nice day to you all =)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to