2

I am new in perl programming. I have tried the basic function and get the below error. Please any one help how to fix the issue.

Can't locate Person.pm in @INC (you may need to install the Person module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at ./oops.pl line 4.
BEGIN failed--compilation aborted at ./oops.pl line 4.

Person.pm file

package Person;

sub new {
   my $class = shift;
   my $self = {
      _firstName => shift,
      _lastName  => shift,
      _ssn       => shift,
   };
   # Print all the values just for clarification.
   print "First Name is $self->{_firstName}\n";
   print "Last Name is $self->{_lastName}\n";
   print "SSN is $self->{_ssn}\n";
   bless $self, $class;
   return $self;
}
sub setFirstName {
   my ( $self, $firstName ) = @_;
   $self->{_firstName} = $firstName if defined($firstName);
   return $self->{_firstName};
}

sub getFirstName {
   my( $self ) = @_;
   return $self->{_firstName};
}
1;

oops.pl file

#!/usr/bin/perl

use Person;

$object = new Person( "Mohammad", "Saleem", 23234345);
# Get first name which is set using constructor.
$firstName = $object->getFirstName();

print "Before Setting First Name is : $firstName\n";

# Now Set first name using helper function.
$object->setFirstName( "Mohd." );

# Now get first name set by helper function.
$firstName = $object->getFirstName();
print "Before Setting First Name is : $firstName\n";

Finally i have run the oops.pl file and get the below error.

Can't locate Person.pm in @INC (you may need to install the Person module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at ./oops.pl line 4.
BEGIN failed--compilation aborted at ./oops.pl line 4.
Kanewilliam
  • 199
  • 2
  • 18
  • 2
    Newer Perls don't have `.` in `@INC` for security reasons. You need `use lib '.'`. But you really ought to put your file in `lib/` and have `use lib 'lib'`. – simbabque Aug 02 '18 at 10:06
  • 1
    That should be `use FindBin qw( $RealBin ); use lib "$RealBin/lib";` – ikegami Aug 02 '18 at 15:14

0 Answers0