It is also an enormous speed hit, and you can already do
that, either by using Symbol and then calling gensym, or
with the following:
my $fh = do {local *FH};
my $file = "foo.txt";
open ($fh, "> $file") or die "Cannot write '$file': $!";
print $fh "Hello world\n";
And yes, you can keep filehandles in arrays, etc.
But note that if you try to abuse this, you could
run out of filehandles in your program. If lots of
programs all open lots of filehandles, you could run out
of filehandles on your machine. So it is best to not leave
a million of these open... | [reply] [d/l] |
Its also out-dated. I beleive the standards now are the IO::blah modules (IO::File, IO::Handle, IO::Pipe, etc) which are also part of the standard, and that FileHandle.pm is only included to support old scripts. I've heard people complain about these as well, but if you try to use STDOUT as an object, perl demands IO::Handle
prompt>perl -we "STDOUT->print('test')"
Can't locate object method "print" via package "IO::Handle" at -e line
+ 1.
prompt>perl -MIO::Handle -we "STDOUT->print('test')"
test
That's using 5.6 (ActiveState 613) on NT4, so I'm not sure how far back this goes. (And yes, that example also works under strict)
| [reply] [d/l] |
| [reply] |