PERL CGI Tutorial
for Writing Interactive Form Scripts

Display a File in a Scrolling Textarea

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

display_textarea.pl

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

print "<html>\n";
print "<head><title></title></head>\n";
print "<body>\n";
print "<textarea cols=30 rows=4>\n";

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

chomp(@array);

@sortedarray=sort(@array);

foreach $line (@sortedarray){
($last,$first)=split(/\|/,$line);
print "File Entry: $first $last\n";
}


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

Remember to Refresh the page after modifications.

Try the Script