home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7777 < prev    next >
Encoding:
Text File  |  1993-01-12  |  2.2 KB  |  65 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!hermes.chpc.utexas.edu!news.utdallas.edu!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: Query - arrays of files
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1993Jan12.180207.1855@news.eng.convex.com>
  8. Date: Tue, 12 Jan 1993 18:02:07 GMT
  9. Distribution: na
  10. Reply-To: tchrist@convex.COM (Tom Christiansen)
  11. References: <C0r02A.526@vuse.vanderbilt.edu>
  12. Nntp-Posting-Host: pixel.convex.com
  13. Organization: Convex Computer Corporation, Colorado Springs, CO
  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. Lines: 46
  18.  
  19. From the keyboard of drl@vuse.vanderbilt.edu (David R. Linn):
  20. :I am having trouble attempting to use arrays of filehandles.  Is this
  21. :supported in perl?  For more details, read on.
  22.  
  23. You have to do something like
  24.  
  25.     $fh = $PTR[$subnet];
  26.  
  27. Then use $fh as an indirect filehandle.
  28.  
  29. :This didn't work and further reading has convinced me that it shouldn't
  30. :have.  However, the idea of using an array of file handles is still
  31. :appealing.  The problem comes in generating the file handle names.
  32. :Would any of you more-experienced folks care to suggest a way to do
  33. :this (or to explain why this is a bad idea)?
  34.  
  35. Here's a sysopen() function that I just wrote today that shows
  36. one way of generating filehandles.
  37.  
  38.     require 'syscall.ph';
  39.     require 'fcntl.ph';
  40.  
  41.     sub sysopen { 
  42.     local($path, $flags, $mode) = @_;
  43.     local($fd, $fh);
  44.     if (($fd = syscall(&SYS_open, $path, $flags, $mode)) == -1) {
  45.         return undef;
  46.     } 
  47.     $fh = 'sysfh' . ++$sysopen'fh;
  48.     open($fh, "+>&$fd") || return undef; # XXX: wrong mode
  49.     return $fh;
  50.     } 
  51.  
  52.     $tty = &sysopen("/dev/tty", &O_RDWR | &O_NDELAY | &O_EXCL, 0444);
  53.     die "sysopen /dev/tty: $!" unless defined $tty;
  54.  
  55.     printf "tty handle is %s, fdesc is %d\n", $tty, fileno($tty);
  56.  
  57.     print $tty "hello, tty!\n";
  58.  
  59. --tom
  60. -- 
  61.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  62.  
  63.  
  64.  "All things are possible, but not all expedient."  (in life, UNIX, and perl)
  65.