Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: initializer method called from object constructor, overwriting the another object's variables

by Old_Gray_Bear (Bishop)
on Oct 08, 2010 at 16:16 UTC ( #864233=note: print w/ replies, xml ) Need Help??


in reply to initializer method called from object constructor, overwriting the another object's variables

The variables $self_ip and $partner_ip are "class variables" (defined in the package, but outside of one of the methods). Consequently they can be seen by all objects instantiated from the package. And as you found out, anything that can be seen by an object can be modified by the object.

If you need them to be part of each object, then they have to be defined in the object by adding them in the new() method --

sub new { my $ip_addr = shift(); my $self = { DEVICE_IP => $ip_addr, self_ip => undef, partner_ip => undef, }; bless $self, 'MyPackage'; $self->my_init(); return($self);

----
I Go Back to Sleep, Now.

OGB


Comment on Re: initializer method called from object constructor, overwriting the another object's variables
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-29 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls