Like I said before, PodMaster demonstrated that 5.8.4 has an alarm function, but it doesn't appear (to me?) capable of interupting IO, which is somewhat limiting in application.

As I also said, there are (usually) other ways of interupting things that take a long time. The problem is that what will work for one thing will not necessarially work for another, so you need to be specific about what it is your doing instead of keep posting the same hypothetical question.

For example, the psuedo problem you've posed could be tackled this way:

#! perl -slw use strict; use Term::ReadKey; $| = 1; sub ReadLine { my $timeout = shift; my $start = time; ReadMode 1; my $buf; while( time < $start + $timeout ) { if( my $c = ReadKey 0.5 ) { printf $c; $buf .= $c; ReadMode( 0 ), return $buf if ord( $c ) == 13; } } ReadMode 0; return undef; } for my $n ( 1 .. 10 ) { if( my $buf = ReadLine( 10 ) ) { print "$n Got $buf"; } else { print "$n timed out"; } } __END__ [16:35:02.57] P:\test>alarmed.pl Subroutine ReadLine redefined at P:\test\alarmed.pl line 7. 1 Got fred 2 Got bill 3 Got John 4 timed out 5 timed out 6 timed out 7 Got blech 8 Got one 9 Got two three 10 Got four

But that almost certainly won't solve your problem. I also previously referred you to this thread Timeouts/timers on Win32 system, which contains a couple of other possible solutions. One using threads and one using Win32::Process.

Which, if any of these solutions might work for your particular problem depends very much on what your real problem is, but keep asking "Why doesn't alarm work", won't make it work.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re: simple timeout by BrowserUk
in thread simple timeout by disciple01

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.