Initializing Attributes In The Constructor : Attributes « Class « Perl






Initializing Attributes In The Constructor

 

package Person;
use warnings;
use strict;
sub new {
    my $class = shift;
    my $self = {@_};
    bless($self, $class);
    return $self;
}
1;



#!/usr/bin/perl
use Person;
my $object = Person->new (
    surname => "G",
    forename => "G",
    address => "Apts.",
    occupation => "tester"
);
print "This person's surname: ", $object->surname, "\n";

   
  








Related examples in the same category

1.Adding A Class Attribute