in reply to Is there a way to halt the program until an enter is pressed?

For the purpose of debugging, or to pause a long report so it can be read in fragments? If you want to pause for debugging use Perl's built in debugger (see perldebug). If on the other hand you wish a pause for UI purposes the following may help:

print "Read this then press enter"; <>; print "Thanks for that.\n";
True laziness is hard work

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

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

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