P
pdpi
Hi all,
I've only just started learning perl a couple of days ago (trying to do
some basic CGI), and have stumbled upon a bit of a doubt. From RTFMing,
I figured that, to print each line of a text file as an HTML paragraph,
something like this works:
#!/usr/bin/perl
use CGI;
my $cgi = new CGI;
open(BODY,"../data/body.txt");
print $cgi->header("text/html");
print $cgi->start_html;
while(<BODY>){
print $cgi->p($_);
}
print $cgi->end_html;
close(BODY);
however, what I want next is to make the file's lines be rendered as
entries in an unordered list/rows in a table (i figure at that point
it's all mostly the same). The obvious way to do this is
print <ul>
while(<BODY>){
print $cgi->li($_);
}
print</ul>
but that feels somewhat lacking in elegance or consistency, especially
considering the existence of the ul function in CGI.pm, but I'm
stumped. It feels as though there ought to be a simple, elegant way to
do this. Any takers?
I've only just started learning perl a couple of days ago (trying to do
some basic CGI), and have stumbled upon a bit of a doubt. From RTFMing,
I figured that, to print each line of a text file as an HTML paragraph,
something like this works:
#!/usr/bin/perl
use CGI;
my $cgi = new CGI;
open(BODY,"../data/body.txt");
print $cgi->header("text/html");
print $cgi->start_html;
while(<BODY>){
print $cgi->p($_);
}
print $cgi->end_html;
close(BODY);
however, what I want next is to make the file's lines be rendered as
entries in an unordered list/rows in a table (i figure at that point
it's all mostly the same). The obvious way to do this is
print <ul>
while(<BODY>){
print $cgi->li($_);
}
print</ul>
but that feels somewhat lacking in elegance or consistency, especially
considering the existence of the ul function in CGI.pm, but I'm
stumped. It feels as though there ought to be a simple, elegant way to
do this. Any takers?