in reply to __DATA__, seek, and tell
Text after __DATA__ but may be read via the filehandle "PACK- NAME::DATA", where "PACKNAME" is the package that was current when the __DATA__ token was encountered. The filehandle is left open pointing to the contents after __DATA__. It is the program's responsibility to "close DATA" when it is done reading from it. For compatibility with older scripts written before __DATA__ was introduced, __END__ behaves like __DATA__ in the toplevel script (but not in files loaded with "require" or "do") and leaves the remaining contents of the file acces- sible via "main::DATA".See SelfLoader for more description of __DATA__, and an example of its use. Note that you cannot read from the DATA filehandle in a BEGIN block: the BEGIN block is executed as soon as it is seen (during compi- lation), at which point the corresponding __DATA__ (or __END__) token has not yet been seen.
So, there's even a core module using that feature. I'm not sure about scoping, though, i.e. what is happening when you have multiple files of the same package (e.g. via AutoLoader), and have thus multiple __DATA__ tokens present. I guess __DATA__ is file scoped, but I didn't try it. I've used that before, too. See Re: $. - smarter than you might think and follow-ups.
You might want to check RFC: Sub::Auto - lazy loading revisited (now: AutoReloader) for another way of reloading changed files automatically, although that code is still alpha.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|