in reply to Re^2: Is there a way to halt the program until an enter is pressed?
in thread Is there a way to halt the program until an enter is pressed?

... print "Press <Enter> to continue, or 'q' to quit: "; my $input = <STDIN>; exit if $input eq "q\n"; ...

(Note that <> reads lines, so - strictly speaking - they'd have to enter q<Enter>... In case that could be an issue, you might want to choose a different wording for the prompt.)

Or tell them to use Ctrl-C.

And make a subroutine out of the snippet if you need it more than once.

Replies are listed 'Best First'.
Re^4: Is there a way to halt the program until an enter is pressed?
by Anonymous Monk on Mar 14, 2011 at 00:38 UTC

    It just waits without printing the print statement,I mean it is already expecting a user input without printing the print statement.\

    print "Press <Enter> to continue, or 'q' to quit: "; my $input = <STDIN>; exit if $input eq "q\n";

        Can you advise where should I set $| to 1,right before the print statement?