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
|