in reply to Re^3: uninitialized value $_
in thread uninitialized value $_

That works. I thought (incorrectly obviously) that $_ automatically was assigned the last line read. I recall seeing examples like that, but maybe it was only for reading from files.

Replies are listed 'Best First'.
Re^5: uninitialized value $_
by LanX (Saint) on Mar 29, 2016 at 00:08 UTC
    > $_ automatically was assigned the last line 

    That's a special DWIM magic within the while condition only!

    while (<>) {

    ... which is Perl shorthand for the more explicitly written version: ...

    while (defined($line = <ARGV>)) {

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      ... but not documented under while, but in perlop under "I/O-Operators" (where the internal link anchor seems not to work)
        I've already updated an excerpt of the documentation in perlsyn, but yes perlop is indeed clearer, thanks!

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re^5: uninitialized value $_
by Marshall (Canon) on Mar 28, 2016 at 22:26 UTC
    Perhaps a better thought model is that $_ gets assigned the last thing read. At the end of the file, that last thing is the EOF, which is returned as undef.

    The fundamental problem here was poor loop design. The use of for(;;){} or while (1){} should be restricted to very special circumstances like an infinite loop in server code to wait for next connection, etc. If the loop is coded differently and I would argue properly, as corion suggests, while (<>){}, this handling undef inside the loop problem goes away.