in reply to Re^2: Deleting EOF from a file
in thread Deleting EOF from a file

I was intrigued by the question and had a go at trying to do it. I often find myself using a hex dump utility to 'see what's actually there'. Looking in Perl would be useful. I've not had experience with binary mode before so it was about time I did.
(dummy.txt has 99 'a's and a 'b')
use strict; use warnings; use Fcntl; my $stream; # 'or die ...' removed for clarity sysopen(DUMMY, "dummy.txt", O_RDWR | O_BINARY); my $bytes_read = read DUMMY, $stream, 128; for ( my $i=0; $i<= $bytes_read; $i++ ){ my $char = substr( $stream, $i, 1 ); print $i, ": ", ord( $char ), " => *", $char, "*\n"; }
produces...
0: 97 => *a* 1: 97 => *a* 2: 97 => *a* 3: 97 => *a* ... etc 98: 97 => *a* 99: 98 => *b* 100: 0 => **
Nowhere near it (not even new lines). I found the docs quite intimidating, clearly the cross platform issues are tricky. (I was reading one article that mentioned CP/M!)
Any pointers?
activestate 5.8 on winXP

Replies are listed 'Best First'.
Re^4: Deleting EOF from a file
by graff (Chancellor) on Jul 17, 2004 at 15:18 UTC
    How did you create "dummy.txt"? I haven't been keeping up with all the hidden details of recent MS Windows versions -- it may well be that the practice of appending ^Z to mark EOF on text-mode files has been abandoned.

    I happened to try creating a small text file using Notepad on an XP system just now, and I found that there was no ^Z at the end. But I do recall seeing text files created on MS systems in the mid-90's that had been transfered (using binary-mode ftp) to a unix system, and there was a ^Z at the end of each file.

      Thanks for your reply.

      ...it may well be the practice of appending ^Z to mark EOF on text-mode files has been abandoned.

      I've come to that conclusion too. I'm still rooting around on Google to learn how Windows marks EOF in text files. I now have a little hex dump script so it would be useful to know.
      Thanks again.