If that's your entire code you're missing a couple of things like the open() and login() methods.
Not sure the purpose of the serverid hash with a single key\value, but here's what the code should be with a hash:
use strict;
use warnings;
use Net::Telnet;
my ($username, $password)=("benlaw", "usertesting");
my $serverid{'testsvr1'} = '10.159.32.21';
my $t = new Net::Telnet (Timeout => 10,
Dump_Log=> "err_dump.log",
Output_log=> "err_out.log",
Prompt => "/\$\s/" );
my @date;
while ( my ($key,$value) = each(%servid){
$t->open($key=>$value);
$t->login($username,$password);
@date = $t->cmd("date");
print @date;
$t->close;
}
Here's the way I would write it if I had a single server to log into:
use strict;
use warnings;
use Net::Telnet;
my ($username, $password)=("benlaw", "usertesting");
my $serverid = "10.159.32.21";
my $t, @date;
$t = new Net::Telnet (Timeout => 10,
Dump_Log=> "err_dump.log",
Output_log=> "err_out.log",
Prompt => "/\$\s/" );
$t->open($serverid);
$t->login($username, $password);
@date = $t->cmd("date");
print @date;
$t->close;
|