Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: CGI: newlines, write exactly "\r\n" to end the headers, then turn off binmode

by haukex (Archbishop)
on Mar 10, 2018 at 11:40 UTC ( [id://1210610]=note: print w/replies, xml ) Need Help??


in reply to CGI: newlines, write exactly "\r\n" to end the headers, then turn off binmode

First, I agree with the others that the best way to go is CGI.pm's header function.

I can do that with binmode(STDOUT), but then how do I turn off binmode() for STDOUT, so that I can then print regular text in the response body?

I don't think this part of the question has been answered, so yes, you can call binmode on a handle as often as you like. See the following example, in which I've shown how I would do it if I wanted to be sure Perl was sending CR+LF to STDOUT (or in this case, the currently selected handle, normally STDOUT).

$ cat test.pl binmode select, ':crlf'; print "\x{FC}\n"; binmode select, ':raw'; print "\x0D\x0A"; binmode select, ':encoding(UTF-8)'; print "\x{FC}\n"; $ perl -wMstrict test.pl | hexdump -C 00000000 fc 0d 0a 0d 0a c3 bc 0a |........| 00000008

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-06-18 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    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.