PERL CGI Tutorial
for Writing Interactive Form Scripts

Display a File in a Table

Simple modifications can be made to display_file.pl to display the multi line file in a table. The code includes the sorting routine and the split function. A chomp function is added to remove new line characters from the array.

display_table.pl

#!/usr/bin/perl
print "Content-type:text/html\n\n";

print "<html>\n";
print "<head><title></title></head>\n";
print "<body>\n";
print "<table cellpadding=5 border=1>\n";
print "<tr><th>First Name</th><th>Last Name</th></tr>\n";

open(INFO, "names.txt");
@array=<INFO>;
close (INFO);

chomp(@array);

@sortedarray=sort(@array);

foreach $line (@sortedarray){
($last,$first)=split(/\|/,$line);
print "<tr><td>$first</td><td>$last</td></tr>\n";
}

print "</table>\n";
print "</body>\n";
print "</html>\n";

Remember to Refresh the page after modifications.

Try the Script

Searching a File Working with Numbers
CGI Online is a service provided by Net Success 2000 Plus Inc.
PO Box 1508
Somerset, KY 42502
Last Modified: January 21, 2008

| HTML TOC | Website Design Workshop | Home |