Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: CGI http header error

by arthas (Hermit)
on Jun 03, 2003 at 13:04 UTC ( [id://262645]=note: print w/replies, xml ) Need Help??


in reply to CGI http header error

The script you posted doesn't send anything to the standard output, therefore you get an error when you browse it. Try the following variation:
#!/usr/bin/perl use strict; use CGI; my $q = new CGI; $doc = $q->start_html('hello world'); $doc .= $q->h1('hello world'); $doc .= $q->end_html; open(OUT, '>out.html') || die "Couldn't open out file: $!"; print OUT $doc; close OUT; print $q->header(); print $doc;

This sends the HTML code both to out.html and to the standard output (that it to say, to the web browser).

The HTTP header (print $q->header()) is needed when outputting to the standard output via CGI, but you can (and maybe you'd better) not send it to the file you create. The example above works this way: the header is only sent to the browser, and the HTML file is sent both to the browser and to the file.

Michele.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-19 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found