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

charles.e.derykus at boeing.com charles.e.derykus at boeing.com
Tue Sep 28 21:17:39 CDT 1999


> 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]

typeglobs still give me the willies :)

For instance, here're some magic that only
the magician could love: 

  print STDOUT  "foo";         # ok 
  print main::STDOUT  "foo";   # ok
  print  *STDOUT  "foo";        # error
  print  \*STDOUT  "foo";        # error

but, surround 'em with curly braces, and
there're fine:

  print { *STDOUT }  "foo";      # ok
  print { \*STDOUT }  "foo";     # ok

Seeing that, you might logically think:

  open(STDOUT, "+</dev/tty") or die "open failed: $!'

would work while the following would fail: 

  open(*STDOUT, "+</dev/tty") or die "open failed: $!'
  open(\*STDOUT, "+</dev/tty") or die "open failed: $!'

Nope - no problem with any of 'em.  


--
Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    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