Perl programming on MPE/iX - February 2001

February 9, 2001
Solution Symposium
Page 31
hp e3000
perl
programming
object definitions example - Foo.pm
package Foo;
sub new { # method subroutine
my ($class_name) = @_;
my ($self) = {}; # create an empty hash to store attributes
bless ($self, $class_name); # make it an object
$self->{'_created'} = 1;
return $self;
}
sub put { # method subroutine
my ($self, $data) = @_;
$self->{_bar} = $data; # store data in the _bar attribute
}
sub get { # method subroutine
my ($self) = @_;
return $self->{_bar}; # return data from the _bar attribute
}
1; # return code for use statement