Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: how to use angle operator with timeout?

by tobyink (Canon)
on Feb 03, 2013 at 23:35 UTC ( [id://1016876]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1016876]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found