note
hippo
<p>These first few points don't relate directly to your question but
rather to your code. I hope you don't mind.</p>
<blockquote><i><c>
print start_html(-title =>'Senders',
-bgcolor=>'#95B8DB');
</c></i></blockquote>
<p>I wouldn't do that and nor would the maintainer of [metamod://CGI]
who says
"[https://metacpan.org/pod/distribution/CGI/lib/CGI.pod#HTML-Generation-functions-should-no-longer-be-used|HTML
Generation functions should no longer be used]". For the reasons listed
there this is best avoided.</p>
<blockquote><i><c>
use CGI ':standard';
</c></i></blockquote>
<p>If you took the advice not to use the HTML
Generation functions then you probably don't need this line either
because all you are using the rather heavy CGI module for now is
printing the header. But that's one immutable line of output so just
use</p>
<code>
print "Content-Type: text/html; charset=utf-8\n\n",
</code>
<p>and be done with it.</p>
<blockquote><i><c>
system("sudo grep -E 'Passed CLEAN.* ->.*' /var/log/maillog | grep -v root@ > /tmp/PassedCLEAN.txt");
system("sudo awk '{print \$12}' /tmp/PassedCLEAN.txt > /tmp/PassedCLEAN_1.txt");
system('sed -e "s/<\(.*\@.*\)>/\1/g" /tmp/PassedCLEAN_1.txt > /tmp/PassedCLEAN_2.txt');
</c></i></blockquote>
<p>I really, really wouldn't do that. You are shelling out from perl to
run 2 greps, an awk and a sed: three utilities which perl supercedes in
99% of cases. Think about how you could do all of this from within perl
instead.</p>
<p>Turning to your question, I would replace your output stanza of</p>
<blockquote><i><c>
for my $word (sort keys %count) {
print "$word $count{$word}\n";
#print "$count{$word}\n";
print "<br />";
print " \n";
}
close $fh;
</c></i></blockquote>
<p>with something which leverages the HTML table element. eg:</p>
<code>
print '<table><tr><th>Word</th><th>Count</th></tr>';
for my $word (sort keys %count) {
print "\n<tr><td>$word</td><td>$count{$word}</td></tr>";
}
print '</table>';
</code>
<p>Or, for a bar chart:</p>
<code>
print '<table><tr><th>Word</th><th>Count</th></tr>';
for my $word (sort keys %count) {
print "\n<tr><td>$word</td><td>" . ('#' x $count{$word}) . "</td></tr>";
}
print '</table>';
</code>
<p>When you are happy with this principle you can go further and abstract
it with a template if you wish, eg. [metamod://Template].</p>
1214725
1214725