in reply to Re: Not Catching Signals While Program is Prompting with IO::Prompt
in thread Not Catching Signals While Program is Prompting with IO::Prompt

found this bug... https://rt.cpan.org/Ticket/Display.html?id=38014
  • Comment on Re^2: Not Catching Signals While Program is Prompting with IO::Prompt

Replies are listed 'Best First'.
Re^3: Not Catching Signals While Program is Prompting with IO::Prompt
by BrowserUk (Patriarch) on Jun 08, 2012 at 21:37 UTC

    2008. It doesn't look like anythings going to change any time soon.

    Frankly, the module is overkill for what it does. A simple loop that prompts and re-prompts until the input matches a regex is pretty trivial to write.

    sub promptTill{{ local $\; print "$_[0]: "; chomp( my $input = <STDIN> ); redo unless $input =~ $_[1]; return $input }} print promptTill( 'Yes/No', qr[^(?:y(?:e(?:s)?)?|n(?:o)?)$]i );;

    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.

    The start of some sanity?

      I agree. I ended up with this:
      use Time::HiRes qw(usleep); my $PROMPT="What's the ticket number?\n"; my $TRY_AGAIN_PROMPT="excuse me?\n"; my $TICKET_NUMBER=prompt_until($PROMPT, $TRY_AGAIN_PROMPT, '^\d{7}$|^NOTICKET$', 1500); sub prompt_until { my $prompt_text=$_[0]; my $try_again_prompt=($_[1])? $_[1] : ''; my $until_regex=($_[2])? $_[2] : '.*'; my $speed=($_[3])? $_[3] : '0'; my $answer; if ($speed) { print_slow($prompt_text,$speed); } else { print "$prompt_text"; } $answer=<STDIN>; until ($answer=~m/$until_regex/) { if ($speed) { print_slow($try_again_prompt,$speed); } else { print "$try_again_prompt"; } $answer=<STDIN>; } chomp $answer; return $answer; } ###################################################################### +########## sub print_slow { my $speed=pop(@_); my $phrase=join('',@_); my @characters=split(//,$phrase); foreach my $char (@characters) { print $char; usleep($speed); } } ###################################################################### +##########

        Good for you. It is nice to have control of your code isn't it.

        One comment though. What is the point of print_slow()?

        At 1500 microseconds per, your 25 character prompt will appear completely in 0.0375 of a second. No human being will ever notice the difference.

        And if you increased it to the point where is became noticeable -- say 50000 per or there abouts -- it will just piss off your users.

        It would me anyway! When I install new versions of windows one of the first things I do is disable all those damn artificial delays to menus, pointless animations, and the like; they just irritate me.


        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.

        The start of some sanity?

      I still don't understand the code!

        You've been a member for a whole 35 minutes and you still don't understand it. Wow!

        Have you tried running it yet?


        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.

        The start of some sanity?