Differences between current version and previous revision of perlfaq5(1).
Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 2 | Last edited on Tuesday, June 4, 2002 12:22:34 am | by perry | |
Older page: | version 1 | Last edited on Tuesday, June 4, 2002 12:22:34 am | by perry | Revert |
@@ -60,9 +60,9 @@
select((select(OUTPUT_HANDLE), $ = 1)[[0]);
Or if don't mind slowly loading several thousand lines of module code just because you're afraid of the $ variable:
- use FileHandle;
+ use !
FileHandle;
open(DEV,
or the newer IO::* modules:
@@ -222,15 +222,15 @@
The fastest, simplest, and most direct way is to localize
the typeglob of the filehandle in question:
- local *TmpHandle;
-Typeglobs are fast (especially compared with the alternatives) and reasonably easy to use, but they also have one subtle drawback. If you had, for example, a function named ''TmpHandle()'', or a variable named %TmpHandle, you just hid it from yourself.
+ local *!
TmpHandle;
+Typeglobs are fast (especially compared with the alternatives) and reasonably easy to use, but they also have one subtle drawback. If you had, for example, a function named ''!
TmpHandle()'', or a variable named %!
TmpHandle, you just hid it from yourself.
sub findme {
-local *HostFile;
-open(HostFile,
+local *!
HostFile;
+open(!
HostFile,
Here's how to use typeglobs in a loop to open and store a bunch of filehandles. We'll use as values of the hash an ordered pair to make it easy to sort the hash in insertion order.
@names = qw(motd termcap passwd hosts);
@@ -243,23 +243,23 @@
For passing filehandles to functions, the easiest way is to preface them with a star, as in func(*STDIN). See ``Passing Filehandles'' in perlfaq7 for details.
If you want to create many anonymous handles, you should
-check out the Symbol, FileHandle, or IO::Handle (etc.)
+check out the Symbol, !
FileHandle, or IO::Handle (etc.)
modules. Here's the equivalent code with Symbol::gensym,
which is reasonably light-weight:
foreach $filename (@names) {
use Symbol;
my $fh = gensym();
open($fh,
-Here's using the semi-object-oriented FileHandle module, which certainly isn't light-weight:
+Here's using the semi-object-oriented !
FileHandle module, which certainly isn't light-weight:
- use FileHandle;
+ use !
FileHandle;
foreach $filename (@names) {
-my $fh = FileHandle-
+my $fh = !
FileHandle-
Please understand that whether the filehandle happens to be a (probably localized) typeglob or an anonymous handle from one of the modules in no way affects the bizarre rules for managing indirect handles. See the next question.
__How can I use a filehandle indirectly?__
@@ -271,13 +271,13 @@
$fh = SOME_FH; # bareword is strict-subs hostile
$fh =
-Or, you can use the new method from the FileHandle or IO modules to create an anonymous filehandle, store that in a scalar variable, and use it as though it were a normal filehandle.
+Or, you can use the new method from the !
FileHandle or IO modules to create an anonymous filehandle, store that in a scalar variable, and use it as though it were a normal filehandle.
- use FileHandle;
-$fh = FileHandle-
+ use !
FileHandle;
+$fh = !
FileHandle-
use IO::Handle; # 5.004 or higher
$fh = IO::Handle-
Then use any of those as you would a normal filehandle. Anywhere that Perl is expecting a filehandle, an indirect filehandle may be used instead. An indirect filehandle is just a scalar variable that contains a filehandle. Functions like print, open, seek, or the diamond operator will accept either a read filehandle or a scalar variable containing one:
@@ -798,9 +798,9 @@
You can use the builtin getc() function for most
filehandles, but it won't (easily) work on a terminal
device. For STDIN , either use the
-Term::ReadKey module from CPAN or use the
+Term::!
ReadKey module from CPAN or use the
sample code in ``getc'' in perlfunc.
If your system supports the portable operating system
@@ -834,12 +834,12 @@
return $key;
}
}
END { cooked() }
-The Term::ReadKey module from CPAN may be easier to use. Recent versions include also support for non-portable systems as well.
+The Term::!
ReadKey module from CPAN may be easier to use. Recent versions include also support for non-portable systems as well.
- use Term::ReadKey;
+ use Term::!
ReadKey;
open(TTY,
For legacy DOS systems, Dan Carson
@@ -869,27 +869,27 @@
# 10-19 ALT QWERTYUIOP
# 1E-26 ALT ASDFGHJKL
# 2C-32 ALT ZXCVBNM
# 3B-44 F1-F10
-# 47-49 HOME,UP,PgUp
+# 47-49 HOME,UP,!
PgUp
# 4B LEFT
# 4D RIGHT
-# 4F-53 END,DOWN,PgDn,Ins,Del
+# 4F-53 END,DOWN,!
PgDn,Ins,Del
# 54-5D SHF F1-F10
# 5E-67 CTR F1-F10
# 68-71 ALT F1-F10
-# 73-77 CTR LEFT,RIGHT,END,PgDn,HOME
+# 73-77 CTR LEFT,RIGHT,END,!
PgDn,HOME
# 78-83 ALT 1234567890-=
-# 84 CTR PgUp
+# 84 CTR !
PgUp
This is all trial and error I did a long time ago; I hope I'm reading the file that worked...
__How can I tell whether there's a character waiting on a
filehandle?__
The very first thing you should do is look into getting the
-Term::ReadKey extension from CPAN . As we
+Term::!
ReadKey extension from CPAN . As we
mentioned earlier, it now even has limited support for
non-portable (read: not open systems, closed, proprietary,
not POSIX , not Unix, etc)
systems.