Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  Perl Tutorials
Perl Introduction
Variables
Operators
Character Meanings
Control and Loops
Functions
Array Functions
String Functions
Math Functions
Reading and Writing
Using Cookies
Printing a file
Hit Counter
Poll Receiving
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

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 
<< Previous | Next >>

Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com