Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Data inheritance

by perlbaski (Acolyte)
on Sep 23, 2011 at 18:44 UTC ( #927599=note: print w/ replies, xml ) Need Help??


in reply to Re: Data inheritance
in thread Data inheritance

Hi ikegami, Thank you for yor replies. The packages are not in the same file. CommonObject is meant to be used by multiple child class objects. I just put all the common variables in the CommonObject.

So the question is, which is better:

Make the array variable a ref variable and do $self->$common_array_ref=1,1;

or make it package scope variable.


Comment on Re^2: Data inheritance
Re^3: Data inheritance
by ikegami (Pope) on Sep 23, 2011 at 19:31 UTC

    Between the two options you gave, I would go with the one that compiles.

    Of course, it's not between the two options you gave. What's with using global variables, especially one that gets clobbered every time you create an object.

      Is there any other way of doing this apart from using global variables. I want to have common data variables in CommonObject.pm which I want to set in child class depending upon the type of child I create.

      Also, I cannot seem to be able to set parent class variables in child class even with declaration using 'our'.

      Looks like using exporter module is the only way to go.

        Is there any other way of doing this apart from using global variables.

        Don't know. What are you doing? So far, you've only asked how to set a global variable. (You said class var, but that's the same thing.)

        Also, I cannot seem to be able to set parent class variables in child class even with declaration using 'our'

        Reread what I said: "which means you can access the array as @CommonObject::common_array from anywhere."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927599]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-09-02 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls