in reply to __END__ is equivalent to __DATA__ ?

The perl Cookbook recipe 7.6 says they are the same...

<snippet from the book>

__DATA__ and __END__ indicate the logical end of a module or script before the physical end of the file is reached. Text after __DATA__ or __END__ can be read through the per-package DATA filehandle. For example, take the hypothetical module Primes. Text after __DATA__ in Primes.pm can be read from the Primes::DATA filehandle.

__END__ behaves as a synonym for __DATA in the main package. Text after__END__ tokens in modules is inaccessable.

  • Comment on Re: __END__ is equivalent to __DATA__ ?

Replies are listed 'Best First'.
•Re^2: __END__ is equivalent to __DATA__ ?
by merlyn (Sage) on Dec 08, 2004 at 13:55 UTC
    Text after __DATA__ in Primes.pm can be read from the Primes::DATA filehandle.
    Ahh, too bad I didn't get to review that book... I could have marked that sentence as a technical error. As perldata clearly states:
    Text after __DATA__ but may be read via the filehandle "PACK- NAME::DATA", where "PACKNAME" is the package that was current w +hen the __DATA__ token was encountered.
    So, what matters is not the name of the file, but rather the "current package" at the point just before the __DATA__ token. I'm surprised Nat and Tom made such a straightforward mistake. (I've just submitted this as an errata for the book, so hopefully future books will get it right.)

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.