in reply to Re^6: Passing a file handle to a sub. I still don't get it.
in thread Passing a file handle to a sub. I still don't get it.

One warning: when you use <> or readline in while, assigned to a simple scalar (or by default to $_), perl automatically puts a defined() around your condition, like:
while ( defined( my $line = readline($fh) ) )
which keeps the loop from prematurely terminating if the $line read happens to be false. This is not done for you using the OO methods.

Replies are listed 'Best First'.
Re^8: Passing a file handle to a sub. I still don't get it.
by Anonymous Monk on Jun 10, 2005 at 20:57 UTC
    Don't worry about false lines. That is only possible when he mucks with $/ or the input line is broken with ^D which is possibly entered to leave the while.
      ^D should yield an eof, which should result in readline returning undef, not "", so the defined() wouldn't make a difference.

      A false line happens without mucking with $/ when you have a 0 at the end of a file, not followed by a newline.