Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 examining the Monastery: (9)
As of 2014-12-25 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls