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

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?

  • Comment on Re^3: Not Catching Signals While Program is Prompting with IO::Prompt
  • Download Code

Replies are listed 'Best First'.
Re^4: Not Catching Signals While Program is Prompting with IO::Prompt
by gg48gg (Sexton) on Jun 12, 2012 at 21:42 UTC
    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?

        It is certainly noticeable. There are several prompts in the program I wrote. The print_slow is to differentiate and emphasize the new output from the output that was output previously. It is quite effective.

        I tuned the speed so the messages require very little waiting, but the user can still tell what just printed to the screen. Sounds dumb, I know, but you have to see a whole run of the program before and after the print_slow implementation in order to understand. I suspect the IO:Prompt module had this functionality for the same reason.

Re^4: Not Catching Signals While Program is Prompting with IO::Prompt
by locked_user indoposting (Initiate) on Jun 08, 2012 at 22:26 UTC
    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?