Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: EOF character

by cdarke (Prior)
on Sep 25, 2006 at 08:50 UTC ( [id://574700]=note: print w/replies, xml ) Need Help??

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>; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://574700]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-06-15 01:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.