programming-examples/perl/Class/Passing Parameters to Instance Methods.pl

28 lines
522 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
# Module: House.pm
#!/bin/perl
package House;
sub new{
my $class = shift;
my ($owner, $salary, $style) = @_;
my $ref={ "Owner"=>$name,
"Price"=>$salary,
"Style"=>$style,
};
return bless($ref, $class);
}
sub display {
my $self = shift;
foreach $key ( @_){
print "$key: $self->{$key}\n";
}
}
1;
# main.pl
#!/bin/perl
use House;
my $house = House->new("A", 2, "House");
$house->display ("Owner", "Style");