programming-examples/perl/Class/Initializing Attributes In The Constructor.pl

22 lines
375 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
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";