Printing a file in Perl
The following code will print a file to standard output. When responding to client queries through the webserver, whatever is printed to the standard output is sent to the client computer by the web server.
#!/usr/local/bin/perl
print "Content-type: image/gif","\n\n"; #MIME header for web server
open(GIFILE,"perl1.gif") || die "<center>
<H3>Cannot open gif file.</H3></center>";
while (read(GIFILE, $buf, 8192))
{
print $buf;
}
This Example prints an HTML file to the standard output and thereby sends it to the client web browser:
#!/usr/bin/perl
# ospoll.pl
# A Perl program that draws a Web page.
print "Content-type: text/html", "\n\n"; # MIME header.
open(HTMLFILE, "ospoll.html") || die "
<center><H3>Sorry, I cannot open HTML pollfile.</H3></center>";
while (read(HTMLFILE, $buffer, 16384)) #Print the Poll HTML file
{
print $buffer;
}
close(HTMLFILE);
# End ospoll.pl
|
|