home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!stl!sbil!wet!spitws117!jim
- From: jim@spitws117.sbil.co.uk (James Gillespie)
- Newsgroups: comp.lang.perl
- Subject: Prompting for input
- Message-ID: <1992Sep8.141620.12312@sbil.co.uk>
- Date: 8 Sep 92 14:16:20 GMT
- Sender: news@sbil.co.uk
- Reply-To: jim@spitws117.sbil.co.uk
- Organization: Salomon Brothers International Limited
- Lines: 40
-
- Yes, it's me again. Hopefully this problem won't be quite such an own
- goal :-) It is this: I decided to write a little script to execute a
- given command on a lot of arguments. It worked fine. Then I thought
- I'd add a couple of options so that it would say what it was about to
- do, and wait for a keyboard input before proceeding. Then I thought,
- "how about a command to skip this occurrence?". I came up with this
- (slightly stripped down):
-
- $command = shift(@ARGV);
-
- COMMAND:
- foreach $file (@ARGV)
- {
- print "'$command $file'";
- $ans = getc;
- exit if $ans eq "q";
- next COMMAND if $ans eq "n";
-
- system $command, $file;
- }
-
- This works fine as long as you want to either execute everything or
- quit part way through, but if you type "n\n" to skip an instance, it
- skips that instance alright but executes the next one without a
- pause. It appears to me that there must be something left on STDIN
- as a result of entering the string "n\n", but I can't find anything
- in the Camel book about such an occurrence, or how to "suck"
- everything off STDIN without sending an EOF. Setting $| doesn't
- appear to have any effect.
-
- Does anybody have any idea what's going on and how to fix it?
-
- Perl version 3.0.1.9, patch level 41
-
- Thanks,
-
- Jim Gillespie ----------------------------------------------------
- jim@sbil.co.uk Salomon Brothers International Limited
- +44 71 721 2672 ---------------------------------------------------
- "Three strikes and you're history, kiddo!" - Calvin's mom
-