home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!pnl-oracle!toysrus!d3c572
- From: ds_curtis@pnl.gov (DS Curtis)
- Newsgroups: comp.lang.perl
- Subject: Re: write
- Message-ID: <1992Jul29.203913.8498@oracle.pnl.gov>
- Date: 29 Jul 92 20:39:13 GMT
- Article-I.D.: oracle.1992Jul29.203913.8498
- References: <1992Jul23.155101.22025@noose.ecn.purdue.edu>
- Sender: news@oracle.pnl.gov
- Reply-To: ds_curtis@pnl.gov
- Organization: Battelle PNL
- Lines: 36
-
-
- In article 22025@noose.ecn.purdue.edu, newlin@purcell.ecn.purdue.edu (Johnny N.) writes:
- >Is there any way to make write send its output to a buffer instead
- >of a filehandle? The only way that I could figure out to do this
- >is to send the output to a temporary file and then read it back in.
- >Needless to say, this is less than efficient.
- >
- >-John
- > newlin@ecn.purdue.edu
-
- I have seen this question quite a few times so I thought I would reply.
-
- I found a pretty good solution that uses write to format data that I then
- process and does not use files:
-
- pipe (READ_HANDLE, WRITE_HANDLE);
- if (fork == 0) { # Child Process.
- close (READ_HANDLE);
- print (WRITE_HANDLE "Whatever Processing and printing goes here\n");
- close (WRITE_HANDLE);
- exit 0;
- }
- close (WRITE_HANDLE); # Parent Process.
- @OUTPUT_FROM_CHILD = <READ_HANDLE>; # Parent Process.
-
- If you want to buffer the output (from child) or input (to parent) then
- set $| = 1;
-
- I hope this is something like what you are looking for.
-
- +------------------------------------------------------------------------+
- | Name: Darren Curtis | Disclaimer: My opinion in my own! |
- | Company: Battelle PNL | Theory: Bo Knows UNIX - But Doesn't |
- | Phone: (509) 375-2152 | Have Time to !@#$ with it!! |
- | email: ds_curtis@pnl.gov | This space left blank intentionally! |
- +------------------------------------------------------------------------+
-