if statement - Uninitialized Value on Perl code -
i have been looking @ code can't figure out following error: uninitialized value $match in string eq perl
basically code connects telnet several device , closes connection. test users , passwords see ones expired. when connects gives success message otherwise gives failure message.
i not know why giving me uninitialized value error. code using project:
$telnet = new net::telnet ( errmode => "return", port => $puerto, input_log => $output_log, host => $host ); $conexion = $telnet -> open(timeout => 5); if ($conexion == 1) { print "se conecto al $host \n\n"; $input = $telnet -> get(timeout => 10); if ($input) { if ($input =~ /login name:/){ $cmd = $telnet -> print($user); ($prematch, $match) = $telnet -> waitfor( timeout => 5, match => '/password:/'); if ($match) { $cmd = $telnet -> print($password); ($prematch, $match) = $telnet -> waitfor( timeout => 5, match => '/windows/'); if ($match) { $cmd = $telnet -> print(""); ($prematch, $match) = $telnet -> waitfor( timeout => 5, match => '/choose/'); # aca se tiene que diseƱar el caso de errores de clave //////error line////// if ($match eq "choose") { //////error line////// $cmd = $telnet -> print("2"); ($prematch, $match) = $telnet -> waitfor( timeout => 5, match => '/corp/'); if ($match) { print "se autentico satisfactoriamente el usuario y la contrasena\n\n"; } } else { print "el usuario o contrasena son erroneos, fallo la conexion\n\n"; $cerrar = $telnet -> close; } } } } } } $cerrar = $telnet -> close; }
i'm guessing
$telnet->waitfor()returned empty list- or @ list either 1 element
- or perhaps
undefvalue second element.
you see, "uninitialized" doesn't mean same thing means in other languages. might have had in $match before assigned undefined value. perl, whether or not ever defined value scalar, or assigned undefined value same.
that might of confusion is.
a lot of apis in perl return empty list, in list context, when fail. way "truth value" 0, can this:
unless (( $prematch, $match ) = $telnet->waitfor( timeout => 5, match => '/choose/' )) { die 'failed waiting telnet!'; }
Comments
Post a Comment