home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5288 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.3 KB  |  42 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!fendahl.dev.cdx.mot.com!mcook
  3. From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
  4. Subject: Re: Help with named pipes
  5. Message-ID: <mcook.713657379@fendahl.dev.cdx.mot.com>
  6. Sender: news@merlin.dev.cdx.mot.com (USENET News System)
  7. Nntp-Posting-Host: fendahl.dev.cdx.mot.com
  8. Organization: Motorola Codex, Canton, Massachusetts
  9. References: <3310@ra.nrl.navy.mil> <1992Aug12.162224.3119@rock.concert.net> <1992Aug12.163401.5091@news.eng.convex.com> <1992Aug12.192105.5316@rock.concert.net>
  10. Date: Wed, 12 Aug 1992 22:09:39 GMT
  11. Lines: 29
  12.  
  13. cole@concert.net (Derrick C. Cole) writes:
  14.  
  15. >if (-p $pipe) {
  16. >   open(FIFO, "$pipe") || die "can't open\n";
  17. >   while (<FIFO>) {
  18. >      read(FIFO, $buf, 120);
  19. >      chop($buf);
  20. >      print "|$buf|\n";
  21. >   }
  22. >}
  23.  
  24. The <FIFO> expression is going to read a newline-terminated line from <FIFO>.
  25. That's probably not what you want...
  26.  
  27. >Now, 120 is an arbitrary number out of the air.  What I'd really like is for
  28. >read() to place in $buf a null-terminated string as written by the other end,
  29. >and not just 120 characters.  Am I completely blind, is there a way to do
  30. >this, neither, or both?
  31.  
  32. How about this:
  33.  
  34.   $/ = "\000";        # the input record separator
  35.   while (<FIFO>)
  36.   {
  37.     chop;        # discard the \0
  38.     print "|$_|\n";
  39.   }
  40.  
  41. Michael.
  42.