Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should use CGI.pm's header method to output the Content-Type header?

Tags:

header

cgi

perl

If I'm using the CGI module in Perl, I can do this

$cgi = CGI->new();
$cgi->header(-type=>"text/html");

Or go for the classic

print "Content-Type: text/html\r\n\r\n";

Does it matter which we use? Is there any difference between the two? Both seem to work.

For me I'd go for the first if I was using CGI anyway, but if not then I wouldn't bother loading the module for just one action. But just wondering if there is any thing on the subject?

Psy

like image 313
Psytronic Avatar asked Oct 20 '25 02:10

Psytronic


1 Answers

Strictly speaking, you have to print \r characters:

print "Content-Type: text/html\r\n\r\n"

is a legal way to express what you want to say.

Generally, I'd stick with what CGI offers. It allows much more concise and readable code, and CGI knows a lot more about such details than you do.

like image 111
reinierpost Avatar answered Oct 22 '25 14:10

reinierpost