patch based on @TomFairbairn, check $eof after $fread