home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4943 < prev    next >
Encoding:
Internet Message Format  |  1992-07-24  |  1.5 KB

  1. Path: sparky!uunet!pmafire!news.dell.com!swrinde!cs.utexas.edu!hermes.chpc.utexas.edu!news.utdallas.edu!convex!tchrist
  2. From: tchrist@convex.COM (Tom Christiansen)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: write
  5. Message-ID: <1992Jul24.161333.23225@news.eng.convex.com>
  6. Date: 24 Jul 92 16:13:33 GMT
  7. References: <1992Jul23.155101.22025@noose.ecn.purdue.edu>
  8. Sender: usenet@news.eng.convex.com (news access account)
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. Organization: CONVEX Realtime Development, Colorado Springs, CO
  11. Lines: 27
  12. Originator: tchrist@pixel.convex.com
  13. Nntp-Posting-Host: pixel.convex.com
  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.  
  18. From the keyboard of newlin@purcell.ecn.purdue.edu (Johnny N.):
  19. :Is there any way to make write send its output to a buffer instead
  20. :of a filehandle?  The only way that I could figure out to do this
  21. :is to send the output to a temporary file and then read it back in.
  22. :Needless to say, this is less than efficient.
  23.  
  24. The workaround way is to fork a child of yourself with open to "|-"
  25. to do that kind of thing for you
  26.  
  27.     die "can't fork: $!" unless defined ($pid = open(KID, "|-"));
  28.     if ($pid) {
  29.     select(KID);
  30.     # now write() to KID
  31.     } else {
  32.     while (<STDIN>) {
  33.         # now do what you want
  34.     } 
  35.     exit;
  36.     } 
  37.  
  38.  
  39. --tom
  40. -- 
  41.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  42.  
  43.  
  44.     It's all magic.  :-)        --Larry Wall in <7282@jpl-devvax.JPL.NASA.GOV>
  45.