in reply to dos EOF in linux

EOF is ascii 26 (control-z). As long as you are reading the text file normally, the eof function should be sufficient. Note that it returns 1 if the next read will return an end of file or if the filehandle is not open.

perlfunc has the following Practical hint: you almost never need to use eof in Perl, because the input operators typically return undef when they run out of data, or if there was an error.

Replies are listed 'Best First'.
Re: Re: dos EOF in linux
by shemp (Deacon) on Jan 21, 2003 at 18:00 UTC
    well, the problem is that the dos eof appears on its own line, so when im processing the lines, heres what happens:
    ... open INPUT_HANDLE .... or die ... while ( my $line = <INPUT_HANDLE> ) { chomp $line; last if my_eof_test($line, \*INPUT_HANDLE); process_line($line); } close(INPUT_HANDLE); ...
    i feel that i need this test because otherwise, the line that contains just the EOF will read properly, because there it is data, even though its the DOS EOF. because the read is true, we get in the while loop, and the line containing just EOF gets sent to process_line(). am i missing something here?
      As far as I know this isnt an issue. But im a win32 user. :-)

      And may I point out that

      while ( my $line = <INPUT_HANDLE>) {
      is not the same as (excepting the variable used)
      while ( <INPUT_HANDLE> ) {
      I believe that should read
      while ( defined ( my $line= <INPUT_HANDLE> ) ) {
      But personally I dont see the point. You shouldnt be afraid of using $_.

      --- demerphq
      my friends call me, usually because I'm late....

      It shouldn't matter but if you are worried about processing the EOF marker, try this...

      ... open INPUT_HANDLE .... or die ... while ( my $line = <INPUT_HANDLE> ) { chomp $line; process_line($line); last if eof(INPUT_HANDLE); } close(INPUT_HANDLE); ...