Hi, I'm trying to create an object instant variable inside the constructor of another class, but the instant variable is not recognized after initialized. Could anyone help me on this one, please.
use Net::Telnet(); package L_Switch; sub new { my $class = shift; my $location = shift; my $ip = shift; my $self = {}; $self -> {'ip'} = $ip; $self -> {'location'} = $location; $self -> {'full_info'} = "asd"; $self -> {'fault'} = ""; $self -> {'time_out'} = ""; $self -> {'telnetConn'} => new Net::Telnet( Timeout => 10, errmode => # if connection is unsucces +sful ( sub { $self -> {'full_info'} = CLIENT . ",," . $ip . ",T +IMEOUT"; $self -> {'fault'} = "-No Response"; $self -> {'time_out'} = 1; } ) ); bless $self, $class; return $self; } sub login { my $self = shift; $self -> {'telnetConn'} -> open($self -> {ip}); $self -> {'telnetConn'} -> login(USERNAME, PASSWORD); } 1;
telnetConn is the instant variable that has problems. I tried to use it in Login method, but the error returned is
Can't call method "open" on an undefined value at L_Switch.pm.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |