Alright, it's not "pretty" by way of displaying it to the page, but it does exactly what you want it to do:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
open(INF,"data.txt") or dienice("Can't open data.txt: $! \n");
@grok = <INF>;
close(INF);
print <<EndHdr;
<html><head><title>My Data</title></head>
<body>
<center>
<h2 align="CENTER">My Data</h2>
<table border="1">
<tr>
EndHdr
$cnt = 1;
foreach $i (@grok) {
chomp($i);
($Item,$Page,$Desc,$Pack,$Price) = split(/\|/,$i);
if ($cnt == 5) {
print "<td>$Item</td><td>$Page</td><td>$Desc</td><td>$Pack</td><td>$Price</td>\n";
print "</TR><TR>\n";
$cnt = 1;
} else {
if ($Item ne "") {
print "<td>$Item</td><td>$Page</td><td>$Desc</td><td>$Pack</td><td>$Price</td>\n";
$cnt++;
}
}
}
print <<EndFoot;
</tr>
</table>
</center>
</body>
</html>
EndFoot
sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Offline 2,413 posts
since Dec 2004