Passing Parameters to Instance Methods : Methods « Class « Perl






Passing Parameters to Instance Methods

 

# 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");

   
  








Related examples in the same category

1.The Class and Instance Methods