in reply to Global symbol "$session" requires explicit package name
In addition to what jakobi said above, you might also want to check the return value of Net::Telnet::Cisco->new(). Maybe it wasn't able to establish a connection!
Also, if ( EXPRESSION ) { } else { ... } doesn't earn a beauty award either. I'd suggest you rewrite the whole foreach block like this:
foreach (@matches) { chomp; print "'$_'\n"; my ($p1, $p2) = get_p(); if (my $session = Net::Telnet::Cisco->new(Host => $_) ) { $session->login('myname', $p1); warn "Can't enable: " . $session->errmsg unless $session->enable($p2); my @version = $session->cmd('show version '); print @version, "\n"; } else { die "Couldn't connect to $_"; } } exit;
However, I'm having this hunch that the version thingy is going to be the same for each iteration, so you might also want to consider something like this:
my @version; foreach (@matches) { .... @version ||= $session->cmd('show version '); } print @version, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Global symbol "$session" requires explicit package name
by Bloodnok (Vicar) on Oct 17, 2009 at 01:23 UTC | |
by muba (Priest) on Oct 17, 2009 at 02:17 UTC |