Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: OUTPUT Data to a table or horizontal bar chart by hippo
in thread OUTPUT Data to a table or horizontal bar chart by theravadamonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2021-02-26 13:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?