home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5768 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  1.8 KB

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