CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Error while creating code for inheritance

 



death_metal
Novice

May 24, 2013, 2:27 PM

Post #1 of 6 (1467 views)
Error while creating code for inheritance Can't Post

Hi,
I am trying to inherit class lolol to class L, but when I run the program I get the error:

back.pl is my perl file name

can't locate parent.pm in @INC <@INC contains: c:/Perl/site/lib c:Perl/lib .> at back.pl line 28[\b]

BEGIN FAILED---compilation aborted at back.pl line 28[\b]
line 28 is the line where I have mentioned code for inheriting super class



Code
package lolol; 

use strict;
use warnings;

sub new{
my $gu={
_name=>$_[1],
_age=>$_[2]
};
bless $gu,'lolol';
return $gu;
}
sub metho{
my($self,@arg)=@_;

print "\n",$arg[0];
#print "\n",$reg;
}
sub kol{
my $self=@_;
}
my $ko=new lolol;
print "\n",$ko;
$ko->metho('rajehs',23);

package L;
use parent 'lolol';
use lib;
print "\n";
print "hello";
sub new{
my $cl=@_;
my $r={
_part=>$_[1],
_size=>$_[2]
};
bless $r,$cl;
return $r;
}
my $child=new L('bolt',4);
print "\n";
print $child->{_part};
print $child;
[\code]

I went through net, but found that nothing is missing in respect to this @INC, all I need to mentioned some path.
I tried that, but I code didn't work do that. (used Exporter, etc keywords).

Any help will be greatly appreciated.
Seniors and forum members kindly help me.

Thanks in advance! Smile


death_metal
Novice

May 25, 2013, 6:35 AM

Post #2 of 6 (1451 views)
Re: [death_metal] Error while creating code for inheritance [In reply to] Can't Post

FishMonger please help. [:(]


Laurent_R
Veteran / Moderator

May 25, 2013, 10:15 AM

Post #3 of 6 (1448 views)
Re: [death_metal] Error while creating code for inheritance [In reply to] Can't Post

The error message simply says that you are trying to use the "parent" module and that it does not exist on your Perl installation (@INC is the list of directories where modules can be found).

I think you should simply remove the word "parent" from your use statement:


Code
use lolol;



(This post was edited by Laurent_R on May 25, 2013, 10:18 AM)


FishMonger
Veteran / Moderator

May 25, 2013, 10:35 AM

Post #4 of 6 (1443 views)
Re: [death_metal] Error while creating code for inheritance [In reply to] Can't Post

What version of perl are you using? parent.pm was added to core in v5.10.1. If you're using an older version that would cause the "can't locate parent.pm in @INC" error.

Are both package definitions in the same file, or are they separate files?

You should have them in separate files, but if want them in the same file and you want to setup inheritance, then you need to use the -norequire option/param


Code
use parent -norequire 'lolol';


If you're using an older version, use base instead of parent.
http://perldoc.perl.org/base.html


(This post was edited by FishMonger on May 25, 2013, 10:39 AM)


death_metal
Novice

May 26, 2013, 5:19 AM

Post #5 of 6 (1423 views)
Re: [Laurent_R] Error while creating code for inheritance [In reply to] Can't Post

Hi Laurent,
Thanks for your reply,
but when I do what you said, it throws me an error:

can't locate lolol.pm in @INC <@INC contains: c:/Perl/site/lib c:Perl/lib .> at back.pl line #

BEGIN FAILED---compilation aborted at back.pl line #
Both child and parent class are in same file.
The file in which both packages are back.pl (I haven't named the .pl file as per the class name).


In Reply To
The error message simply says that you are trying to use the "parent" module and that it does not exist on your Perl installation (@INC is the list of directories where modules can be found).

I think you should simply remove the word "parent" from your use statement:


Code
use lolol;




death_metal
Novice

May 26, 2013, 5:22 AM

Post #6 of 6 (1422 views)
Re: [FishMonger] Error while creating code for inheritance [In reply to] Can't Post

Hi FishMonger,
Thank you for your time and reply to my post.

I am using version - v5.10

Yes, both the definitions are in same package.(file name back.pl)

When I try with parent-norequire, it throws me below error:

String found where operator expected at back.pl line # near "norequire 'lolol' "
<Do you need to predeclare norequire?>
syntax error at back.pl line# near "norequire 'lolol'"
Execution of back.pl aborted due to compilation errors.


In Reply To
What version of perl are you using? parent.pm was added to core in v5.10.1. If you're using an older version that would cause the "can't locate parent.pm in @INC" error.

Are both package definitions in the same file, or are they separate files?

You should have them in separate files, but if want them in the same file and you want to setup inheritance, then you need to use the -norequire option/param


Code
use parent -norequire 'lolol';


If you're using an older version, use base instead of parent.
http://perldoc.perl.org/base.html



(This post was edited by death_metal on May 26, 2013, 5:28 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives