SriniK has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks,

I have been working with some of Modifiers example.
!#/usr/bin/perl print "Content-type: text/html\n\n"; $string="I have 5 + 6 Rupees and 6/3 paise"; print "$string\n"; $string=~ s{(\d+\s*[+*/-]\s*\d+)}{$1}eegi; print "$string\n"; $string="India Chennai New yark"; print "$string\n"; $string=~ s{(\b\w+\b)}{su($1)}eg; print "$string\n"; sub su{ $match=shift; $match=~s{(\w+)}{uc($1)}gei; return $match; }
its all working fine. But if i remove "print "Content-type: text/html\n\n";" the same program through error message
Can u guys please explain why

Thanks
Sri

Replies are listed 'Best First'.
Re: Content-type: text/html
by marto (Cardinal) on Mar 14, 2013 at 10:41 UTC
Re: Content-type: text/html
by vinoth.ree (Monsignor) on Mar 14, 2013 at 10:43 UTC

    The first line of our CGI script must be "Content-Type: text/html" and the print statement must have 2 \n characters:

    One to terminate the current line and the second to produce the require blank line between CGI header and data.

    Update: Sorry

      This has nothing to do with their problem. If they remove line printing the header, which is what they are reporting, they get an error. Use a proper framework for dealing with CGI (be it CGI or a 'modern' web framework), stop worrying about manually printing headers.

      Update: Also, printing the header does not have to be the first line of code.