Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Empty STDIN does not exit while loop

by haukex (Bishop)
on May 20, 2017 at 08:28 UTC ( #1190704=note: print w/replies, xml ) Need Help??

in reply to Empty STDIN does not exit while loop

In general I'd recommend avoiding the pattern while(chomp(<$handle>)) because it often suffers from issues (another explanation).

You might also want to consider using a module for prompting.

use IO::Prompt 'prompt'; my $resp = prompt("Foo? ", -yn); use Term::ReadLine; my $term = Term::ReadLine->new; my $line = $term->readline("Bar? ");

Or even this (the advantage being ExtUtils::MakeMaker is a core module, even though it has a completely different purpose):

use ExtUtils::MakeMaker 'prompt'; my $value = prompt("Quz?","n");

The module does have another advantage: "If prompt() detects that it is not running interactively and there is nothing on STDIN or if the PERL_MM_USE_DEFAULT environment variable is set to true, the $default will be used without prompting. This prevents automated processes from blocking on user input."

Update 2020-11-30: See also the more powerful IO::Prompter, simple example here.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-01-24 06:35 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (64 votes). Check out past polls.