Our First Constructor : Constructor « Class « Perl






Our First Constructor

 

package Person;

use warnings;
use strict;
sub new {
    my $self = {};
    bless ($self, "Person");
    return $self;
}
1;


#Now we can use our Person class to create an object:
#/usr/bin/perl

use warnings;
use strict;
use Person;
my $person = Person->new();

   
  








Related examples in the same category

1.The Class Constructor Method
2.Passing Parameters to Constructor Methods