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

  1. Path: sparky!uunet!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: reopening STDOUT as another stream
  5. Message-ID: <1992Sep6.040444.25185@netlabs.com>
  6. Date: 6 Sep 92 04:04:44 GMT
  7. References: <1992Sep5.071243.8404@netlabs.com> <lahv06INN169@jethro.Corp.Sun.COM>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 21
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <lahv06INN169@jethro.Corp.Sun.COM> tmhoff@oogoody.Corp.Sun.COM writes:
  14. : >If you aren't running an ancient version, ordinary open should work
  15. : >fine for that:    open(STDOUT, "| lpr")
  16. : Not quite what I was looking for. I have DEBUG and LOG output streams.
  17. : Sometimes I want DEBUG and LOG to goto STDOUT, sometimes I want them to
  18. : goto different streams. In C use freopen. 
  19.  
  20. Sounds more like you want a dupish thingy then.  You can use >&FILEHANLE
  21. to do that.  Suppose you set up environment variables to say where
  22. to put DEBUG and LOG.
  23.  
  24.     open(DEBUG, $ENV{DEBUG} ? ">$ENV{DEBUG}" : ">&STDOUT");
  25.     open(LOG,   $ENV{LOG}   ? ">$ENV{LOG}"   : ">&STDOUT");
  26.  
  27. or, written sideways,
  28.  
  29.     open(DEBUG, ">" . ($ENV{DEBUG} || "&STDOUT"));
  30.     open(LOG,   ">" . ($ENV{LOG}   || "&STDOUT"));
  31.  
  32. Larry
  33.