Q. What is the correct syntax for defining a class in Perl?
package class_name
Dear candidates you will find MCQ questions of Perl here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question
use strict;
use warnings;
package vehicle;
sub set_mileage{
my $class = shift;
my $self = {
'distance'=> shift,
'petrol_consumed'=> shift
};
bless $self, $class;
return $self;
}
sub get_mileage{
my $self = shift;
my $result = $self->{'distance'} / $self->{'petrol_consumed'};
print "$result\n";
}
my $ob1 = vehicle -> set_mileage(2550, 175);
$ob1->get_mileage();