Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://864233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found