As subject, I have to write a perl script that transforms a log file like:
pippo 2 64 0 2
pippo_a 3 24 0 2
Pippo_b 2 60 0 23
pluto 0 18 0 4
pluto_a 8 25 0 6
paperino 0 11 1 7
paperino_a 0 27 0 10
coyote 0 29 0 7
beepbeep 0 1 0 0
tommy 3 31 0 27
paperone 4 43 1 15
paperone_a 4 52 0 13
benjamin 0 21 1 35
paperina 10 0 0 0
papera 0 0 0 0
quiquoqua 3 26 0 17
quiquoqua_a 3 25 0 3
pochaontas 0 12 0 68
minnie 11 60 3 384
In this html table format:
LINK: http://imageshack.us/a/img90/7238/tabellao.jpg
Now I have write this little perl script, but I've problem to create the write cycle, from the @cells array:
#! /usr/bin/perl
print "Content-type:text/html\r\n\r\n";
use CGI qw(:standard);
use strict;
use warnings;
use DateTime;
my $line;
my $file;
$file='loggi.txt';
open(F,$file)||die("Could not open $file");
print "<html>\n
<style type='text/css'>\n
body {\n
font-family: Verdana, Arial, Helvetica, sans-serif;\n
color: #333;\n
}\n
table {\n
font-size:11px;\n
}\n
td#vtl, td#pool {\n
font-weight: bold;\n
writing-mode: bt-rl;\n
#-webkit-transform: rotate(90deg);\n
#-moz-transform: rotate(90deg);\n
#-ms-transform: rotate(90deg);\n
#-o-transform: rotate(90deg);\n
#transform: rotate(90deg);\n
}\n
.zone tr{\n
border:2px dotted black;\n
}\n
</style>\n
<body>\n
<table border=2>\n
<!--Intestazione-->\n
<tr>\n
<th id='vtl'>houses</th>\n
<th id='pool'>id</th>\n
<th id='host'>name</th>\n
<th id='vergini'>Ver.(*)</td>\n
<th id='riciclabili'>(yes)</th>\n
<th id='vuote'>zero</th>\n
<th id='full'>Full</th>\n
<th id='spazi'>space</th>\n
</tr>\n
<!--Corpo-->\n
<!--VTLA-->";
print "<tr align='center'>\n
<td id='case' rowspan=7>casaa</td>\n
<td id='id' rowspan=7>10</td>\n
<th id='a' colspan=5>pippi</th>\n
<td id='space' rowspan=30>0</td>\n
</tr>";
while ($line=<F>)
{
print "<tr>";
my @cells= split ' ',$line;
foreach my $cell (@cells)
{
if $cell == 'pippo' {
print "<td id='name'>$cell</td>";
print "<td id='a'>$cell</td>";
print "<td id='b'>$cell</td>";
print "<td id='c'>$cell</td>";
print "<td id='d'>$cell</td>";
}}
print "</tr>";
}
close(F);
print "</table>\n
<br/>\n
Situazione aggiornata al".DateTime->now()->strftime("%a, %d %b %Y %H:%M:%S %z")."
</body>\n
</html>";
This is my first long perl script, can someone help me in reasoning?