in reply to Re^2: Cross-namespace problem with lvalue subs? Want?
in thread Cross-namespace problem with lvalue subs? Want?
(This post is substantially the same as what I said in the Chatterbox. I'm posting it here for future reference.)
[...] works, as does reading with <main::DATA>. Freaky.
Every module can have a __DATA__ section, so the file handle DATA is tied to a package.
But that's not special. While there are a few special file handles which are trully global (STDIN, STDOUT, STDERR and ARGV), all others are stored in lexical variables or package variables. For example,
package AA; open(FILE, '<', $ARGV[0]) or die("open: $!\n"); package BB; print(defined(read(FILE, $buf='', 0))?1:0, "\n"); # 0 package AA; print(defined(read(FILE, $buf='', 0))?1:0, "\n"); # 1
|
|---|