Next | February 2001 | Slide #11 |
package Person;
sub new { my ($class) = @_; my $self = { }; bless $self, $class; return $self; }
This constructs a new Person object
The object itself is an empty anonymous hash
bless turns a Perl data structure into an object
It is like putting a sticky label on the object with the class name on it
Before: $self is just a regular hash
After: It is still a hash, but also an object in class $class
Recall that Person->new is like Person::new('Person')
$class here is Person
Next | ![]() |
Copyright © 2001 M-J. Dominus |