Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 imbibing at the Monastery: (6)
As of 2014-10-25 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls