Thanks to all for the excellent information. Phil
On Wed, May 2, 2012 at 2:41 PM, $Bill Luebkert <dbec...@roadrunner.com> wrote: > On 05/02/2012 06:56, Phillip Richcreek wrote: >> >> A recent post used a nice feature for providing test data to a script. >> (See __DATA__ below) I've seen it before but never understood it. How >> does it work? What signals the end of the data to the while (my $line >> =<DATA>) { ? Is this a type of here document? Can someone point me >> where it's descibed in the perl doc? > > > perldata man page: > > Special Literals > The special literals __FILE__, __LINE__, and __PACKAGE__ represent the > current filename, line number, and package name at that point in your > program. They may be used only as separate tokens; they will not be > interpolated into strings. If there is no current package (due to an > empty > "package;" directive), __PACKAGE__ is the undefined value. > > The two control characters ^D and ^Z, and the tokens __END__ and __DATA__ > may be used to indicate the logical end of the script before the actual > end > of file. Any following text is ignored. > > Text after __DATA__ may be read via the filehandle "PACKNAME::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 top level > script (but not in files loaded with "require" or "do") and leaves the > remaining contents of the file accessible 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 compilation), at > which > point the corresponding __DATA__ (or __END__) token has not yet been > seen. > > perlpod man page: > > Embedding Pods in Perl Modules > You can embed Pod documentation in your Perl modules and scripts. Start > your > documentation with an empty line, a "=head1" command at the beginning, > and > end it with a "=cut" command and an empty line. Perl will ignore the Pod > text. See any of the supplied library modules for examples. If you're > going > to put your Pod at the end of the file, and you're using an __END__ or > __DATA__ cut mark, make sure to put an empty line there before the first > Pod > command. > > __END__ > > =head1 NAME > > perl561delta man page: > > Scripts are read in binary mode by default to allow ByteLoader (and the > filter mechanism in general) to work properly. For compatibility, the > DATA > filehandle will be set to text mode if a carriage return is detected at > the > end of the line containing the __END__ or __DATA__ token; if not, the > DATA > filehandle will be left open in binary mode. Earlier versions always > opened > the DATA filehandle in text mode. > ... > > Potential to leak DATA filehandles > Using the "__DATA__" token creates an implicit filehandle to the file > that > contains the token. It is the program's responsibility to close it when > it > is done reading from it. > > This caveat is now better explained in the documentation. See perldata. _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs