>>>>> "Mark" == Mark Fowler <[EMAIL PROTECTED]> writes:

Mark> On Fri, 1 Mar 2002, Paul Makepeace wrote:
>> Mark Fowler wrote: 
>> >    ref($foo) eq "GLOB" 
>> print "We gots ourselves a file here, boys!" if defined *$foo{IO};

Mark> Thanks Nifty.  That works in nearly all cases, apart from maybe when you 
Mark> tie a filehandle.  Quick!  Let's fix that with:

Mark> use Scalar::Util qw(reftype);

Mark> sub filehandle
Mark> {
Mark>    reftype($_[0]) eq "GLOB" && (defined(*{$_[0]}{IO}) || tied *{$_[0]});
Mark> }

Mark> And voila!  It works!  Okay, so it doesn't work for IO::Scalar.  Well, as 
Mark> Randal already pointed out elsewhere in this thread, there is no way to 
Mark> test for that apart from lots of cans and that's not what we want to do 
Mark> here.

Uh, in that case, go back to the other one:

sub is_filehandle_or_symbolic_handle {
  not ref $_[0] # symref
  or UNIVERSAL::isa($_[0], "IO::Handle");
}

sub is_strictly_filehandle {
  ref $_[0] # not string
  and UNIVERSAL::isa($_[0], "IO::Handle");
}

I think that's a lot easier to understand than your mess.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to