Perl/Tk saves your favorite tools | |||
Main back: References in Perl next: OO in Perl -2 |
In Perl, objects are simply references to hashes (in rare cases you could use references to arrays or references to scalars too). The hash stores the data of the actual object. The reference is blessed into a class, which is in Perl represented by a single package. Example: $teacher = {name => 'Mark', awake => 1}; bless $teacher, 'Animal::Human::Male';Now we have one object (referred to by $teacher ), which is
of class Animal::Human::Male .
The call
$teacher->eat('now');will be translated by Perl to Animal::Human::Male::eat($teacher, 'now').
The creation of the object (the creation of a blessed reference to a hash
with data, also called instantiation is per agreement performed
a function called new.
BooksThere are a few books on writing Perl in the OO way: read one.
| ||
Created by Mark Overmeer with PPresenter on 22 May 2000. |