J
Jim Mozley
I have seen a problem using Net::telnet that I can work around but cannot
explain.
I use the following for wait for a particular pattern match in the input
stream:
$session->waitfor(Match => '/mymatch/',
Errmode => 'return')
or die "cannot match it", $session->lastline;
This is as shown in an example in the module documentation.
The only way I can get this to actually die is to use the default errmode
(which is die). If I use error mode return or my own error handling
subroutine the test is always true even when it should not (I have used
input_log and dump_log to check the input).
The way I can get round this is to use a test in a list context e.g.
($prematch, $match) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $match ) {
print "found it\n";
} else {
print "did not find it\n";
}
or even
($ok) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $ok ) {
etc.
What I was originally trying to do was something along the lines of:
unless ( $result = $session->waitfor('/match/') ) {
print "failed to match \"match\" before timeout";
etc.
}
or even
unless ( $session->waitfor('/match/') ) {
etc.
and as a result of trying to work out why this was not working for me
discovered the "context problem". Can anyone explain what I'm doing wrong?
Rather than work on a larger program (where I discovered the problem) I have
replicated this in a much smaller script where I have aimed to follow the
module examples as near as possible, but I still see the issue.
Regards,
Jim
explain.
I use the following for wait for a particular pattern match in the input
stream:
$session->waitfor(Match => '/mymatch/',
Errmode => 'return')
or die "cannot match it", $session->lastline;
This is as shown in an example in the module documentation.
The only way I can get this to actually die is to use the default errmode
(which is die). If I use error mode return or my own error handling
subroutine the test is always true even when it should not (I have used
input_log and dump_log to check the input).
The way I can get round this is to use a test in a list context e.g.
($prematch, $match) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $match ) {
print "found it\n";
} else {
print "did not find it\n";
}
or even
($ok) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $ok ) {
etc.
What I was originally trying to do was something along the lines of:
unless ( $result = $session->waitfor('/match/') ) {
print "failed to match \"match\" before timeout";
etc.
}
or even
unless ( $session->waitfor('/match/') ) {
etc.
and as a result of trying to work out why this was not working for me
discovered the "context problem". Can anyone explain what I'm doing wrong?
Rather than work on a larger program (where I discovered the problem) I have
replicated this in a much smaller script where I have aimed to follow the
module examples as near as possible, but I still see the issue.
Regards,
Jim