In perldata it mentions that __END__ behaves just like __DATA__ in top level scripts. So it's pretty easy to put an __END__ in a script with a bunch of junk after it, and then print "Byte offset: ", tell(DATA), "\n"; in the script prior to the __END__ tag. If you do that, you'll see that the DATA filehandle is sitting at the offset to the first line after the __END__ tag.

Now whether or not Perl is doing trickery behind the scenes that we don't know about, I can't say. It's possible that it's keeping track of where the __END__ was seen but continuing to read through to the end of the file anyway, and then seeking back to where __END__ was found. But I can't think of any reason why it would go to all that trouble. That's probably not happening; the simplest explanation, that it isn't reading the entire file, is probably correct.

Here's an example:

#!/usr/bin/env perl my $string = do { open my $fh, '<', $0 or die "Cannot open $0: $!\n"; local $/ = undef; <$fh>; }; if ($string =~ m/^__END__\n/gm) { print '__END__ tag found at ', pos($string), "\n"; } print 'Entire file length: ', length($string), "\n"; END { print 'DATA filehandle tell offset: ', tell(DATA), "\n"; } __END__ Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country.

This produces the following output:

__END__ tag found at 351 Entire file length: 1892 DATA filehandle tell offset: 351

That seems to indicate that Perl stops reading after it has finished reading the line that contains the __END__.


Dave


In reply to Re: Does perl read the entire pl file into memory? by davido
in thread Does perl read the entire pl file into memory? by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.