How to create a Perl class? How can you call a method?
Answer
- Let's create the package:
Example.pm
package Example;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub is_working {
print "Working!";
}
1;
- Now we can instance the
Exampleclass and callis_workingmethod:
my $e = new Example();
$e->is_working();
# Output: Working!