in reply to (Ovid) Re: I just realized that FILEHANDLES violate use strict
in thread I just realized that FILEHANDLES violate use strict

Afaik it really is a glob. Just one that doesn't live in the package namespace (and thus it has no name) but an anonymous one just like the rest of the lexically scoped vars.

The annoying thing is that I remember reading a much better explaination of this but I cant remember where... Perl5Porters maybe.

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.

  • Comment on Re: (Ovid) Re: I just realized that FILEHANDLES violate use strict

Replies are listed 'Best First'.
Re: Re: (Ovid) Re: I just realized that FILEHANDLES violate use strict
by Juerd (Abbot) on Mar 27, 2002 at 18:09 UTC

    Afaik it really is a glob. Just one that doesn't live in the package namespace (and thus it has no name) but an anonymous one just like the rest of the lexically scoped vars.

    Partly true. With open my $foo, $file, $foo is a reference to a glob, and the glob is not anonymous, because globs can only be in a package. The glob reference $foo can be dereferenced in a normal fashion: *$foo. With *$foo, you'll have a normal glob, like all others. Globs have a string representation that happens to be an asterisk, followed by namespace :: name.

    Consider:

    #!/usr/bin/perl -l { open my $foo, '>', $$ or die $!; print $foo; # GLOB(0x...) print ref $foo; # GLOB print *$foo; # *main::$foo print $foo "Test"; # Test > $$ } # The scope has ended. Because the lexical dies, the file is closed. # The (normally unreachable because of its invalid name) glob # *main::$foo still exists, because globals just don't die. # And they lived happily ev^U


    Writing this, I thought of what would happen if I created a new lexical scope in the already existing bare block. Would the glob clash? I tried:
    { open my $foo, '>', $$ or die $!; print $foo; # GLOB(0x...) print ref $foo; # GLOB print *$foo; # *main::$foo print $foo "Test"; # Test > $$ { open my $foo, '>',"$$.z" or die $!; print $foo; # GLOB(0x...) print ref $foo; # GLOB print *$foo; # *main::$foo <-- !!!!! print $foo "Test"; # Test > $$ } }
    I cannot explain this. The glob has the same stringification, but actually is another glob? Is it local()ized internally?

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

      the glob is not anonymous, because globs can only be in a package

      Actually, as you hint at later, local makes this so that it isn't strictly true. You have to create a glob in a package namespace (at least when writing Perl, probably not so when writing C imbedded in perl), which also gives it a name, but it doesn't have to stay there. I don't know if open also temporarilly creates *{'$foo'} and then moves it out of the symbol table, but the end result is similar to that of:   my $foo= do { local *{'$foo'}; \*{'$foo'}; }; so that none of your *$foos are in any symbol table, and so none of them are the same as *{'$foo'}.

              - tye (but my friends call me "Tye")