?
Solved

Object Inheritance in 5.003

Posted on 2003-03-25
10
Medium Priority
?
166 Views
Last Modified: 2010-03-05

Hello, does anyone know how to get object inheritence working under 5.003 version of Perl?

Normally, you would do:

package My::Package;
our @ISA = qw(My::Parent);

But 5.003 doesn't support "our" as far as I can see ('use of "our" is deprecated' error).

So I tried:

package My::Package;
use base qw(My::Parent);

And got the same error.

So I tried:

use vars qw(@ISA);
package My::Package;
@ISA = use base qw(My::Parent);

But it doesn't look in My::Parent for any methods not present in My::Package.

Any ideas?
0
Comment
Question by:muff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 10

Expert Comment

by:rj2
ID: 8202523
Try to install newer version of Perl?
0
 
LVL 9

Author Comment

by:muff
ID: 8202583

I don't see how installing a newer version of Perl will help me get inheritance working under 5.003.

0
 
LVL 10

Expert Comment

by:rj2
ID: 8204284
Why do you need to use 5.003?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
Sapa earned 1000 total points
ID: 8204354
right syntax is:

package My::Package;
use vars qw(@ISA);
@ISA = qw(My::Parent);

or:

package My::Package;
@My::Package::ISA = qw(My::Parent);


--
Andrey
0
 
LVL 20

Expert Comment

by:jmcg
ID: 8204492
The way we did this before we had "our" was simply

package My::Package;
@ISA = qw(My::Parent);
 .
 .
 .


Somewhere, on one of my machines, I think I have a Perl as old as 5.003 that I can try things on if this doesn't work for you.
0
 
LVL 9

Author Comment

by:muff
ID: 8204502


Thanks Sapa, I'll give it a go.  You think this will work with 5.003 ok?

rj2...  I'm not sure this is particularly on topic, but I'll humor you ;)

Not everyone has complete control over the version of Perl they are running under.  I am one of those people.  My dev system has 5.6 on it, but production is hosted by another company and has 5.003.

I have two options: Get my stuff compatible with 5.003 so I can run it, or to find a host that runs at 5.6 (or host production myself).  I am exploring both options, and my question is me exploring option 1: to see if I can compatibalise my stuff with 5.003 without doing too much damage.

Hope this satisfies your curiosity...

muff
0
 
LVL 9

Author Comment

by:muff
ID: 8204534

Darn.  Actually Sapa,

use vars qw(@ISA);
package My::Package;
@ISA = use base qw(My::Parent);

is nonsense.  It wasn't what I tried at all.  This is my syntax:

use vars qw(@ISA);
package My::Package;
@ISA = qw(My::Parent);

This matches what you said, and also jmcg, if you take into account I am using strict, so I have to have the @ISA var defined somehow.  

But I guess we are all saying that 5.003 does understand @ISA, and will search the packages it finds in it for unknown methods?

Thanks all

muff
0
 
LVL 20

Expert Comment

by:jmcg
ID: 8206560
Putting the vars statement before the package statement creates @ISA in the wrong namespace, doesn't it? It's not that there is a global @ISA that all the packages use together -- there's a separate @ISA in each namespace. Sapa's fully qualified naming should have worked for you, even if you are using strict.
0
 
LVL 9

Author Comment

by:muff
ID: 8208952

Heh, yeah, of course it does.  This was another typo on my part.

This all only seems to work if you "use" the inheritable package as well as doing the @ISA thing.

Does that make sense?
0
 
LVL 5

Expert Comment

by:Sapa
ID: 8209639
> This all only seems to work if you "use" the inheritable package as well as doing the @ISA thing.

Sure. Inheritable class should be loaded. @ISA contains package names, but interpreter does not know how to load it (although often class names and module names are the same, you can put more than one package into one module file...).

--
Andrey
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question