in reply to uninitialized value $_

See readline. If the filehandle (or STDIN in your case) gets closed, readline returns undef.

Your loop is easier written in Perl as:

while( <> ) { last unless /\S/; print FILE; };

Replies are listed 'Best First'.
Re^2: uninitialized value $_
by Anonymous Monk on Mar 28, 2016 at 17:04 UTC
    Are you saying that STDIN is getting opened and closed every time a line is read? I guess that would explain why there is nothing there. :) How about a small variation where I need to print something (a prompt or line number) on the terminal before reading the line (so I couldn't have <> in the loop control)? The (broken) code would be something like:
    while () { print $foo; <>; last unless /\S/; print FILE; }
      <>; just reads a line and throws it away. Perhaps you meant $_ = <>;?
        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.