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

26 lines
561 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
# Module: House.pm
package House;
sub new{
my $class = shift;
my ($owner, $salary) = @_;
my $ref={"Owner"=>$owner,
"Price"=>$price,
};
bless($ref, $class);
return $ref;
}
sub display_object {
my $self = shift;
while( ($key, $value)=each %$self){
print "$key: $value \n";
}
}
1;
# main.pl
#!/usr/bin/perl
my $house1 = House->new("A", 2);
my $house2 = House->new("B", 5);
$house1->display_object;
$house2->display_object;
print "$house1, $house2\n";