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

I have a small script that connects to a remote network element on a given port, issues a command, saves the results into an array using getlines, and then prints the data back to me. My problem (I think) is that the data is output with some very small delays that getlines seems to be interpreting as EOF. If I try to store the output in a single array, I get 17 lines. If I add a second getlines with a second array, I get an additional 21 lines. The third getlines grabs the last line, for a total of 39 lines. The problem is, the number of lines varies, and I can't keep just adding getlines and hoping that I get all the data. Why is getlines doing this? I've tried adding a Timeout to getlines, and to my initial open, but this does nothing. The pertinent lines are below, along with some of my debugging. Thanks for any suggestiions.
$connect = new Net::Telnet (Telnetmode => 0); $connect->open(Host => $hostname, Port => $port); $connect->print("$rtrv"); (@prematch,$match) = $connect->waitfor('/COMPLD/'); @rlines = $connect->getlines; @alines = $connect->getlines; @blines = $connect->getlines; print @rlines; print "\nShoud have all printed there...\n\n"; print @alines; print "\nAnd that was the second array\n\n"; print @blines; print "\n"; print "\nThat is the last of it\n\n";

Replies are listed 'Best First'.
Re: How do I force getlines to get ALL the data?
by merlyn (Sage) on Mar 22, 2001 at 01:36 UTC
      I'm also trying the IO::Socket approach, but I'm having trouble of a different kind now. I get all the data in one array, but I'm unfamiliar with how to terminate the read and send the data back. It automatically sends if I close the connection, but I want to do some give and take across the connection before closing it.