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

  1. Path: sparky!uunet!ogicse!pnl-oracle!toysrus!d3c572
  2. From: ds_curtis@pnl.gov (DS Curtis)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: write
  5. Message-ID: <1992Jul29.203913.8498@oracle.pnl.gov>
  6. Date: 29 Jul 92 20:39:13 GMT
  7. Article-I.D.: oracle.1992Jul29.203913.8498
  8. References: <1992Jul23.155101.22025@noose.ecn.purdue.edu>
  9. Sender: news@oracle.pnl.gov
  10. Reply-To: ds_curtis@pnl.gov
  11. Organization: Battelle PNL
  12. Lines: 36
  13.  
  14.  
  15. In article 22025@noose.ecn.purdue.edu, newlin@purcell.ecn.purdue.edu (Johnny N.) writes:
  16. >Is there any way to make write send its output to a buffer instead
  17. >of a filehandle?  The only way that I could figure out to do this
  18. >is to send the output to a temporary file and then read it back in.
  19. >Needless to say, this is less than efficient.
  20. >
  21. >-John
  22. > newlin@ecn.purdue.edu
  23.  
  24. I have seen this question quite a few times so I thought I would reply.
  25.  
  26. I found a pretty good solution that uses write to format data that I then
  27. process and does not use files:
  28.  
  29.       pipe (READ_HANDLE, WRITE_HANDLE);
  30.       if (fork == 0) {                              # Child  Process.
  31.         close (READ_HANDLE);
  32.         print (WRITE_HANDLE "Whatever Processing and printing goes here\n");
  33.         close (WRITE_HANDLE);
  34.         exit 0;
  35.         }
  36.       close (WRITE_HANDLE);                         # Parent Process.
  37.       @OUTPUT_FROM_CHILD = <READ_HANDLE>;           # Parent Process.
  38.  
  39. If you want to buffer the output (from child) or input (to parent) then
  40. set $| = 1;
  41.  
  42. I hope this is something like what you are looking for.
  43.  
  44. +------------------------------------------------------------------------+
  45. | Name:     Darren Curtis        |  Disclaimer:  My opinion in my own!   |
  46. | Company:  Battelle PNL         |  Theory:  Bo Knows UNIX - But Doesn't |
  47. | Phone:    (509) 375-2152       |           Have Time to !@#$ with it!! |
  48. | email:    ds_curtis@pnl.gov    |  This space left blank intentionally! |
  49. +------------------------------------------------------------------------+
  50.