I'm assuming you're using @pattern_list to hold the return values from expect() like this:

@pattern_list = expect "SWBKPT hit for SLOT";

If that is true, then $pattern_list[0] is the "matched pattern position", $pattern_list[1] is the "error" and $pattern_list[2] is the "successfully matching string". However, to debug this, we need all the values, which is why I asked you to use Data::Dumper.

If you want to print the array values without Data::Dumper, then do something like this:

my @arr = qw( bob sue jane); print "\@arr = " . join(':', @arr) . "\n";
Run example:
my@mybox:~/sandbox $ ./4.pl @arr = bob:sue:jane

The reason all the values are important is because if $pattern_list[4] ("after match") has a value, then that probably means Expect is sending the "\n" before your console program is reading input.

Actually, you know what would be a quicker test of that? Insert a sleep() between your expect() and send() like this:

$expect->expect($timeout,"SWBKPT hit for SLOT"); sleep 2; $expect->send("\n\n");

Of course, this test assumes that it takes less than 2 seconds between when the console program prints "SWBKPT hit for SLOT" and when it prints "Cycles : 332".


In reply to Re^3: Need Help in running Expect script in Perl by jffry
in thread Solved: Need Help in running Expect script in Perl by subhasishn@yahoo.com

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.