in reply to Re: Counting lines as I write them...
in thread Counting lines as I write them...

Regarding your pedant ...

use strict; use warnings; use diagnostics; while (my $line = <DATA>) { print $line; } __DATA__ 0 1 2 3 0
(Note that the last line does not have a carriage return on it - so the last character in the file is '0'.)

Running this with perl 5.8.6 seems to net me all 5 lines (and no carriage return on the last line, leaving my prompt shifted over by one). perlsyn refers to this behaviour (i.e., while implicitly checking definedness rather than truth for file reads) rather off-the-cuff in its examples, but I'm having a hard time finding where this is explicit.

Replies are listed 'Best First'.
Re^3: Counting lines as I write them...
by Fletch (Bishop) on Apr 11, 2005 at 15:43 UTC

    Carp, now I can't remember when that changed. That was the behavior ages ago, and then I think you're right that there was an implicit defined-ness check stuck in sometime. I want to say I hit that with an older (5.6 era) perl sometime recently but I can't reproduce it with 5.6.1.

    Probably just best to remember it can happen in case you're ever messing around with a really old version, and not worry about it otherwise.