home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!hermes.chpc.utexas.edu!news.utdallas.edu!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: Query - arrays of files
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1993Jan12.180207.1855@news.eng.convex.com>
- Date: Tue, 12 Jan 1993 18:02:07 GMT
- Distribution: na
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <C0r02A.526@vuse.vanderbilt.edu>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 46
-
- From the keyboard of drl@vuse.vanderbilt.edu (David R. Linn):
- :I am having trouble attempting to use arrays of filehandles. Is this
- :supported in perl? For more details, read on.
-
- You have to do something like
-
- $fh = $PTR[$subnet];
-
- Then use $fh as an indirect filehandle.
-
- :This didn't work and further reading has convinced me that it shouldn't
- :have. However, the idea of using an array of file handles is still
- :appealing. The problem comes in generating the file handle names.
- :Would any of you more-experienced folks care to suggest a way to do
- :this (or to explain why this is a bad idea)?
-
- Here's a sysopen() function that I just wrote today that shows
- one way of generating filehandles.
-
- require 'syscall.ph';
- require 'fcntl.ph';
-
- sub sysopen {
- local($path, $flags, $mode) = @_;
- local($fd, $fh);
- if (($fd = syscall(&SYS_open, $path, $flags, $mode)) == -1) {
- return undef;
- }
- $fh = 'sysfh' . ++$sysopen'fh;
- open($fh, "+>&$fd") || return undef; # XXX: wrong mode
- return $fh;
- }
-
- $tty = &sysopen("/dev/tty", &O_RDWR | &O_NDELAY | &O_EXCL, 0444);
- die "sysopen /dev/tty: $!" unless defined $tty;
-
- printf "tty handle is %s, fdesc is %d\n", $tty, fileno($tty);
-
- print $tty "hello, tty!\n";
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
-
- "All things are possible, but not all expedient." (in life, UNIX, and perl)
-