I need help with the following code. It does what i want it to, but since I clear the screen and do not update it when i finally ^C my scroll back buffer is filled with garbage. Term::Cap might not be the best way to go, i am trying to keep this to Core Modules due to the difficulties of getting things approved to be installed at work, but if not possible i am open to other modules.
Is there anyway i can just update the screen in place. Also the @host_array will be read from a file so the number of hosts can vary from day to day. Any help would be appreciated or point me in the right direction and i can figure it out.
Thanks,
Sean
#!/usr/bin/perl
use Net::Ping;
use Term::Cap;
@host_array = qw(slag sludge snarl swoop);
$terminal = Term::Cap->Tgetent( { OSPEED => 9600 } );
$clear_string = $terminal->Tputs('cl');
while(1) {
print $clear_string;
# High precision syntax (requires Time::HiRes)
foreach $host (@host_array)
{
$p = Net::Ping->new();
$p->hires();
($ret, $duration, $ip) = $p->ping($host, 5.5);
printf("$host [ip: $ip] is down\n") unless $p->ping($host, 2);
printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\n", 1000 * $duration)
if $ret;
$p->close();
}
sleep 2;
}