http://www.perlmonks.org?node_id=574700


in reply to EOF character

Mr. Schwartz (above) is absolutly correct.
Just to add a little detail, there is no such thing as an EOF character in UNIX. The Control-D you are used to pressing is picked up by the terminal driver, the program at the other end does not recieve the character, it gets an end of file condition (not the same thing).
You can inspect special terminal characters using stty -a (from a shell) and even change the character used using stty eof.
This is different to Microsoft Windows cmd.exe. If you notice you have to press Control-Z then <Return> - the IO engine actually recieves the Control-Z in that case. In Perl you only see that character if the handle has binmode set (but then, you were not going to use Windows anyway).

Replies are listed 'Best First'.
Re^2: EOF character
by ikegami (Patriarch) on Sep 25, 2006 at 15:32 UTC

    That's not quite how things work in Win32. When reading from a file, Ctrl-Z is never special, just like in unix. The behaviour you described only applies when reading from a terminal.

    { open(my $fh, '>', 'deleteme.tmp') or die("Unable to create work file: $!\n"); binmode($fh); print $fh ("abc\r\n\cZ\r\ndef\r\n"); } { open(my $fh, '<', 'deleteme.tmp') or die("Unable to read work file: $!\n"); # Not binmode. print <$fh>; }