home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6887 < prev    next >
Encoding:
Text File  |  1992-11-08  |  2.1 KB  |  60 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!news.oc.com!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: $| for stdin?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Nov7.045809.25737@news.eng.convex.com>
  8. Date: Sat, 7 Nov 1992 04:58:09 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <1992Nov4.235759.14315@utagraph.uta.edu>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. Keywords: stdin $| and life
  14. X-Disclaimer: This message was written by a user at CONVEX Computer
  15.               Corp. The opinions expressed are those of the user and
  16.               not necessarily those of CONVEX.
  17. Lines: 41
  18.  
  19. From the keyboard of turbo@cse.uta.edu (Chris Turbeville):
  20. :I am looking for some way of clearing standard in before every read.
  21. :You know the stdin counter-part of $|.  I have a large program
  22. :responsable for helping non-unices do unix admin things safely but I
  23. :can't seem to keep it from getting a wrong char occasionally.  If the
  24. :enter key is a little sticky then I get default responses when they may
  25. :have wanted to enter something just because their fingers are a little
  26. :heavy.  Does anyone know of a way to flush stdin up to now (by now I
  27. :mean some point in the code) and then read something so these extra \n's
  28. :won't clutter up the place.  I have tried seeks and all sorts of
  29. :trickery but to naught.
  30.  
  31. Here's how Larry did it:
  32.  
  33. void
  34. eat_typeahead()
  35. {
  36. #ifdef PUSHBACK
  37.     if (!typeahead && nextin==nextout)  /* cancel only keyboard stuff */
  38. #else
  39.     if (!typeahead)
  40. #endif
  41.     {
  42. #ifdef PENDING
  43.         while (input_pending())
  44.             read_tty(buf,sizeof(buf));
  45. #else /* this is probably v7 */
  46.         ioctl(_tty_ch,TIOCSETP,&_tty);
  47. #endif
  48.     }
  49. }
  50.  
  51.  
  52. Conversion into Perl is left as an exercise to the reader. :-(
  53.  
  54. --tom
  55. -- 
  56.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  57.  
  58. Besides, it's good to force C programmers to use the toolbox occasionally. :-)
  59.         --Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
  60.