in reply to how to use angle operator with timeout?

Try Prompt::Timeout or IO::Prompter.

The basic technique just involves the alarm function...

use 5.010; use strict; use warnings; use Try::Tiny; my $line; try { local $SIG{ALRM} = sub { die "ALARM\n" }; alarm 10; say "Please enter some text, but quick!"; $line = <>; chomp $line; alarm 0; } catch { my $e = shift; $e =~ /^ALARM/ ? warn("timeout\n") : die($e); }; say "Got: '$line'";
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: how to use angle operator with timeout?
by BrowserUk (Patriarch) on Feb 03, 2013 at 23:55 UTC

    Does that work on *nix? Cos it never times out on Windows.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

        I know that they do not work on win32, and why.

        My question was: can signals -- alarm generated or otherwise -- interrupt blocking IO on *nix in under the auspices of safe-signals?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

      "Does that work on *nix? Cos it never times out on Windows."

      Works for me (on Linux).

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re^2: how to use angle operator with timeout?
by Mark_Galeck (Novice) on Feb 05, 2013 at 08:19 UTC
    Thank you Monks very much, I appreciate your help! Yes this does work for me. Thank you!