... with strict; and warnings; active, when reading from the predefined DATA file handle, you will get a warning if you don't have the while (defined (my $line =<DATA>)){} syntax ... a line with just "0" could evaluate to "false".

I'm confused about what you intended to say in the quoted text. A
    while (<DATA>) { ... }
is always implicitly
    while (defined($_ = <DATA>)) { ... }
or more fundamentally
    while (defined($_ = readline(DATA))) { ... }
for  DATA or any other filehandle. Even if a  '0' with no newline is the last character in a file or  __DATA__ or  __END__ block, no warning will be printed. (IIRC, this became true in a very early, but still non-zero, sub-version of Perl 5 — or was it true even for 5.0.0?) (Update: The following code was tested under ActiveState Perl version 5.8.9.)

File t_read_DATA_1.pl:
# t_read_DATA_1.pl 12oct18waw use warnings; use strict; while (<DATA>) { print; } __DATA__ line the first second line penultimate line is line 3 0
Output:
c:\@Work\Perl\monks\Marshall>od -t x1 t_read_DATA_1.pl | tail 0000120 72 6e 69 6e 67 73 3b 0d 0a 75 73 65 20 73 74 72 0000140 69 63 74 3b 0d 0a 0d 0a 77 68 69 6c 65 20 28 3c 0000160 44 41 54 41 3e 29 20 7b 0d 0a 20 20 20 20 70 72 0000200 69 6e 74 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 5f 0000220 5f 44 41 54 41 5f 5f 0d 0a 6c 69 6e 65 20 74 68 0000240 65 20 66 69 72 73 74 0d 0a 73 65 63 6f 6e 64 20 0000260 6c 69 6e 65 0d 0a 70 65 6e 75 6c 74 69 6d 61 74 0000300 65 20 6c 69 6e 65 20 69 73 20 6c 69 6e 65 20 33 0000320 0d 0a 30 0000323 c:\@Work\Perl\monks\Marshall>perl t_read_DATA_1.pl line the first second line penultimate line is line 3 0

Another way to see this is by deparsing:

c:\@Work\Perl\monks\Marshall>perl -MO=Deparse,-p t_read_DATA_1.pl use warnings; use strict 'refs'; while (defined(($_ = <DATA>))) { print($_); } __DATA__ line the first second line penultimate line is line 3 t_read_DATA_1.pl syntax OK 0
See O and B::Deparse. (I think the final  "0" appears in console output before the  "syntax OK" message because the  "0" is not terminated by a newline and doesn't get flushed until the process ends. The  "syntax" message may also be going to STDERR. Or something like that...)

Update: I really should have mentioned that the preceding code was run under ActiveState Perl version 5.8.9, the ancientest Perl I hold in captivity.


Give a man a fish:  <%-{-{-{-<


In reply to Re^4: how do I "initialize" $_ (updated) by AnomalousMonk
in thread how do I "initialize" $_ by Anonymous Monk

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.