| Next | February 2001 | Slide #17 |
Compare:
Person->new(); Person::new('Person');
$hamlet->age(); Person::age($hamlet);
Person->new(...); Person::new('Person', ...);
$hamlet->age(...); Person::age($hamlet, ...);
The -> operator is doing almost the same thing in each case
Perl does not distinguish between class and object methods
It's not unusual to have a method that can be called both ways:
sub new {
my $self = shift;
my $class = (ref $self) || $self;
my $new = (ref $self) ? {%$self} : {};
...
bless $new, $class;
}
# Call this as either of:
Person->new(...);
$p->new();
| Next | ![]() |
Copyright © 2001 M-J. Dominus |