Regarding ISA and Inheritance

P

palemmahesh

Hi,

Iam new to perl and I have some doubt regarding ISA of inheritance.

Suppose /tmp/base/base.pm and /tmp/derived/derived.pm files are present
in my file system.

I want to inherit base.pm into the derived module.

how should I write ISA in derived.pm.

One morething is that both modules are in different paths/directories.

and say the above paths are not present in the @INC array.

So Can Anyone please suggest me how I can inherit the above situation.
Thanks and Regards,
Mahesh
 
S

Sherm Pendley

Iam new to perl and I have some doubt regarding ISA of inheritance.

Suppose /tmp/base/base.pm and /tmp/derived/derived.pm files are present
in my file system.

I want to inherit base.pm into the derived module.

how should I write ISA in derived.pm.

There's no way to tell, from the information you've given. Packages are
used in inheritance, not file paths.

sherm--
 
M

Mahesh

Sherm,

base.pm and derived.pm are perl modules.

and I want to inherit base.pm into derived.pm perl module.

just Iam saying that both the perl modules are in different
directories.

Thanks and Regards,
Mahesh
 
S

Sherm Pendley

Mahesh said:
and I want to inherit base.pm into derived.pm perl module.

just Iam saying that both the perl modules are in different
directories.

It doesn't matter what directories they're in. @ISA contains class
names, not file names. You haven't said what classes (i.e. packages) are
declared in those files, so it's impossible to say what their @ISAs
should look like.

In the simplest case, where the classes are named "base" and "derived",
@derived::ISA might be declared in "derived.pm" like this:

package derived;
our @ISA = qw(base);

Have a look at:

perldoc perlboot
perldoc perltoot
perldoc perltooc
perldoc perlbot

Also, have you read the posting guidelines that appear here about twice
a week?

sherm--
 
J

John Bokma

Randal said:
Sherm> In the simplest case, where the classes are named "base" and
Sherm> "derived", @derived::ISA might be declared in "derived.pm" like
this:

Sherm> package derived;
Sherm> our @ISA = qw(base);

And keep in mind that lowercase package names are reserved, especially
the one called "base", which already does most of what you're looking
for:

package Derived;
use base qw(Base);

IIRC the documentation that comes with Perl (perltoot et al) still use the
@ISA way. Of course I prefer use base :)

PS: Did you like Veracruz?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top