in reply to OUTPUT Data to a table or horizontal bar chart
These first few points don't relate directly to your question but rather to your code. I hope you don't mind.
print start_html(-title =>'Senders', -bgcolor=>'#95B8DB');
I wouldn't do that and nor would the maintainer of CGI who says "HTML Generation functions should no longer be used". For the reasons listed there this is best avoided.
use CGI ':standard';
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
print "Content-Type: text/html; charset=utf-8\n\n",
and be done with it.
system("sudo grep -E 'Passed CLEAN.* ->.*' /var/log/maillog | grep -v +root@ > /tmp/PassedCLEAN.txt"); system("sudo awk '{print \$12}' /tmp/PassedCLEAN.txt > /tmp/PassedCLEA +N_1.txt"); system('sed -e "s/<\(.*\@.*\)>/\1/g" /tmp/PassedCLEAN_1.txt > /tmp/Pas +sedCLEAN_2.txt');
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.
Turning to your question, I would replace your output stanza of
for my $word (sort keys %count) { print "$word $count{$word}\n"; #print "$count{$word}\n"; print "<br />"; print " \n"; } close $fh;
with something which leverages the HTML table element. eg:
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>';
Or, for a bar chart:
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>';
When you are happy with this principle you can go further and abstract it with a template if you wish, eg. Template.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: OUTPUT Data to a table or horizontal bar chart
by theravadamonk (Scribe) on May 18, 2018 at 10:47 UTC | |
by hippo (Bishop) on May 18, 2018 at 10:55 UTC | |
by theravadamonk (Scribe) on May 18, 2018 at 11:41 UTC |