The Class Constructor Method : Constructor « Class « Perl

The Class Constructor Method


# Module:
package House;                 # Class

sub new {                      #constructor
     my $class = shift;
     my $ref={"Owner"=>undef,   
              "Price" =>undef,  
     bless($ref, $class);
     return $ref;    # A reference to the object is returned

# The User of the Module)
use House;
my $houseref = House->new();
print ref($houseref),".\n";


Related examples in the same category

1.Our First Constructor
2.Passing Parameters to Constructor Methods