


|
CGI Scripts to Create a Website with Interactive Features
Read a File and Display Contents
This script uses the file you saved in the previous exercise. Or you can copy the text file names_file.txt provided below to your cgi-bin directory and use it.
read_file.pl
This script will open the file names_file.txt, remove the field separator using the split function of Perl and display the contents to the screen.
#!/usr/bin/perl
open(INFO, "names_file.txt"); # Open db for reading and display
@array=<INFO>;
close (INFO);
print "Content-type:text/html\n\n"; #Content Header
print "<html>\n";
print "<head><title>Display File Contents</title></head>\n";
print "<body>\n";
print "<h4>This script displays the contents of names_file.txt.</h4>\n";
foreach $line (@array){
($last,$first)=split(/\|/,$line);
print "$first $last<br>\n";
}
print "</body>\n";
print "</html>\n";
Test this Script
|

Home

MoonFruit
LIVE JOURNAL
CalgaryPlanet
More websites
Free Website Builders
Web Hosting Services
Web Hosting FAQ
Recommended Web Hosts
|