tsk1979 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I have a subroutine, in which user gives a server_list_array which containts the list of server ips. I then look through each server name, telnet and try to login. If it is a faliure, I make that line in server_list_array null(""). Later I can grep {\S}, @server_list_array to remove the failed servers. Am attaching the code, but the script dies when a server is encountered to which I cannot telnet, even though Errmode is set to 'return'. What is wrong here?
sub server_test_routine { for $i (0..$#SERVER_LIST_ARRAY) { $server_name = $SERVER_LIST_ARRAY[$i]; chomp($server_name); $server_status = 0; $server_test = Net::Telnet->new( Timeout => 10, Prompt => '/]/i', Host => $server_name, Errmode => 'return'); print "Server $server_name returned $server_test\n"; $server_status = $server_test->login(Name => $username,Passwor +d => $password,Errmode => 'return'); $server_test->close; if (!$server_status){ print "Rejecting server $server_name, cannot telnet\n"; $SERVER_LIST_ARRAY[$i] = ""; } } }

Replies are listed 'Best First'.
Re: Testing for valid servers in Net::Telnet
by spadacciniweb (Curate) on Mar 24, 2006 at 08:45 UTC
    I would try different Errormode... and I would see the behavior of the script.