equick has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a simple bit of code in my program which is failing to return control back after the user has entered input

print "Do you wish to continue? (yes/no): "; chomp ($resp=<>); print "resp=$resp\n";

It doesn't print anything after typing and hitting enter (just a newline), so I am stuck on how to fix this. Any help appreciated.

Thanks,

Ed.

Replies are listed 'Best First'.
Re: program hangs on user input
by Anonyrnous Monk (Hermit) on Jan 28, 2011 at 10:27 UTC

    Works fine for me.  Maybe you've accidentally changed the input record sepaprator $/ ?

      Thanks! That's exactly what I did.
Re: program hangs on user input
by cdarke (Prior) on Jan 28, 2011 at 11:25 UTC
    This code might not do what you expect if there is something in @ARGV. The diamond operator <> will try to read files specified in @ARGV (command-line arguments) before reading STDIN if none are present. So it is safer to:
    $resp = <STDIN>;
      Thanks, that's a good tip.
Re: program hangs on user input
by Anonymous Monk on Jan 28, 2011 at 12:58 UTC
    #!/usr/bin/perl -w print "Do you wish to continue (yesno)" ; chomp ($resp=<STDIN>); print "resp=$resp";