in reply to Re: 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?

Basically I want to give the user the option to proceed or exit out of the program.Please advise how can i do that?

  • Comment on Re^2: Is there a way to halt the program until an enter is pressed?

Replies are listed 'Best First'.
Re^3: Is there a way to halt the program until an enter is pressed?
by GrandFather (Saint) on Mar 12, 2011 at 09:58 UTC

    Then why didn't you say so? How about you define the whole problem so we don't have to go through the whole painful question and answer deal then we can give an appropriate answer to the whole problem.

    And just in case you want to think about solving it for yourself you might dig through perlop's 'I/O Operators' section.

    True laziness is hard work
Re^3: Is there a way to halt the program until an enter is pressed?
by Eliya (Vicar) on Mar 12, 2011 at 09:59 UTC
    ... 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.

      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";