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

Hi Monks, I have one line in a program I'm automating that will prompt sometimes, not always. How can I make an expect line "optional". In other words, if you don't see the string before the timeout is reached, don't send anything back. Here's the block I want to make optional.

$expect->expect($timeout,"Do you want to preserve the port number");
$expect->send("n\n");

Thanks very much for any insight.
-Adam

  • Comment on perl Expect question - how to "optionally" expect a string?

Replies are listed 'Best First'.
Re: perl Expect question - how to "optionally" expect a string?
by zwon (Abbot) on Nov 06, 2009 at 19:45 UTC
    if(defined ($expect->expect($timeout,"Do you want to preserve the port + number"))) { $expect->send("n\n"); }
      Thanks zwon! :)