package Student; use warnings; use strict; sub new { my $type = shift; my $class = ref($type) || $type; my $self = { name => shift // "No name", score => shift // 0, }; return bless( $self, $class ); } sub name { my $self = shift; $self->{'name'} = shift // $self->{'name'}; return $self->{'name'}; } sub score { my $self = shift; $self->{'score'} = shift // $self->{'score'}; return $self->{'score'}; } 1; #### #!/usr/bin/perl -l use warnings; use strict; use Student; # the module used my $std = Student->new(); print join " - " => ( $std->name(), $std->score() ); # prints No name - 0 my $std2 = Student->new( "melchi", 78 ); print join " - " => ( $std2->name(), $std2->score() ); # prints melchi - 78 print join " - " => ( $std->name("kunle"), $std2->score(90) ); # prints kunle - 90