I need to exit a loop when getlines times out. The documentation says:
@lines = $obj->getlines([Timeout => $secs,]);
This method reads and returns the next available lines of data from the object. You can use input_record_separator() to change the notion of what separates a line. The default is "\n".

If a line isn't immediately available, this method blocks waiting for one or more lines, or time-out. You can override the object's timeout for this method using $secs. Also see timeout().

On eof a null array is returned. On time-out or other errors, the error mode action is performed.

A null array is returned for both eof and time-out when errmode is not set to "die". Use eof() and timed_out() to distinguish.

And:

timed_out - time-out indicator $boolean = $obj->timed_out; $prev = $obj->timed_out($boolean); This method indicates if a previous read or write method timed-out. With no argument this method returns true if a previous method timed-out. With an argument it sets the indicator. Normally, only internal methods set this indicator.

So how do I make use of this? I want to exit the following loop when timed_out is true, so that I can execute another command.

while (@rlines = $connect->getlines(Timeout =>1)) { print @rlines; }

Timed_out is a boolean value right? According to the info above, I figured I should just be able to say:

while (@rlines = $connect->getlines(Timeout =>1)) { if ($pop->timed_out) { print "Do something else\n"; exit; } print @rlines;

But this isn't working for me. The value of $pop->timed_out is null.

Edit 2001-03-22 by tye


In reply to timed_out usage? by Galen

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.