diff options
author | Gisle Aas <aas@bergen.sn.no> | 1997-06-24 15:46:11 +1200 |
---|---|---|
committer | Tim Bunce <Tim.Bunce@ig.co.uk> | 1997-08-07 00:00:00 +1200 |
commit | c9de509e331450a10058399280ce28f68f0faf39 (patch) | |
tree | 47a8372734a66a69c05b54c67eeb5d9083a315b5 /lib/FileHandle.pm | |
parent | 44ed422101809141bc33c2b85c1cff357de4d7bf (diff) | |
download | perl-c9de509e331450a10058399280ce28f68f0faf39.tar.gz |
bless file handles as FileHandle if loaded else IO::Handle
Subject: Re: More info regarding the Can't locate error message [PATCH]
lvirden@cas.org (Larry W. Virden) writes:
> use FileHandle;
> STDERR->open("/tmp/errorsfile","w");
This patch tries to fix the problem by auto-blessing handles as
'FileHandle' if the FileHandle package has been loaded and IO::Handle
otherwise. The snag is that STDOUT, STDIN, STDERR are initialized
before 'use FileHandle' executes, so they are all initially blessed as
IO::Handles. We compensate by reblessing them in FileHandle.pm:
This makes Larry's example as well as the following code work:
use FileHandle;
open(F, "/dev/null") or die;
F->seek(0, 1) or die;
p5p-msgid: hyb80drrz.fsf@bergen.sn.no
Diffstat (limited to 'lib/FileHandle.pm')
-rw-r--r-- | lib/FileHandle.pm | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/FileHandle.pm b/lib/FileHandle.pm index 0b5d9edcb4..1dc699c85b 100644 --- a/lib/FileHandle.pm +++ b/lib/FileHandle.pm @@ -93,6 +93,11 @@ sub pipe { ($r, $w); } +# Rebless standard file handles +bless *STDIN{IO}, "FileHandle"; +bless *STDOUT{IO}, "FileHandle"; +bless *STDERR{IO}, "FileHandle"; + 1; __END__ |