SPUG: Looking for a graceful way to deal with file handles and modules

Doug Beaver dougb at scalar.org
Tue Sep 28 20:38:51 CDT 1999


On Tue, Sep 28, 1999 at 06:13:17PM -0700, Andrew Sweger wrote:
> On Sep 28, 1999 @ 4:10pm, Doug Beaver wrote:
> 
> :} Filehandles are by definition globals, so you can't refer to it by
> :} package name (I did a quick grep of the pods and didn't see anything
> :} saying they weren't globals, so someone slap me if I'm wrong). 
> 
> Eh? I thought that globals where in fact symbol table entries and thus
> available via the package name. Doug, say it ain't so! :)

Ack, I was completely wrong...  You're right, globals go in the symbol
table and as such can be accessed by package name:

#!/usr/bin/perl

open(F, ">blah") || die $!;
my $fd = fileno(F);
print "File descriptor is [$fd]\n";

package blah;

my $fd = fileno(F);
print "File descriptor is [$fd]\n";
my $mainfd = fileno(main::F);
print "File descriptor is [$mainfd]\n";
1;
__END__
File descriptor is [3]
File descriptor is []
File descriptor is [3]

I hereby prostrate myself in front of the SPUG membership and humbly beg
forgiveness for leading others astray, I don't know what I was
thinking...  The only thing I can offer in my defense is that I'm sick
and had just woke up from a nice nap.  ;-)

So, please ignore my statement about not being able to refer to
filehandles by package name, but please give Symbol::gensym() a try,
it's a lot more lightweight than using FileHandle if all you want is
an anonymous filehandle.

I'm going to go back to bed now.  ;-)

Doug

-- 
Smithers: I'm afraid we have a bad image, Sir.  Market research shows
          people see you as somewhat of an ogre.
   Burns: I ought to club them and eat their bones!

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list