frenchface:

OK, I think you're still short on details. I think you should have at least described the table you wanted. However, your code suggests a simple table layout, so I'll just use that. Also, as I've never used CGI, you'll have to bear with me, and perform any cleanup required.

I'm assuming (based on the code you provided) that you want to build a table something like:

<table> <tr><th>File</th><th>Word</th><th>Count</th></tr> <tr><td>..file1..</td><td>..word1..</td><td>..count..</td></tr> <tr><td>..file1..</td><td>..word2..</td><td>..count..</td></tr> ... <tr><td>..file1..</td><td>..wordn..</td><td>..count..</td></tr> <tr><td>..file2..</td><td>..word1..</td><td>..count..</td></tr> <tr><td>..file2..</td><td>..word2..</td><td>..count..</td></tr> ... ... ... <tr><td>..filem..</td><td>..wordn..</td><td>..count..</td></tr> </table>

So I read a little[1] of perldoc CGI, and it looks like you could do something like this:

# We'll build the table rows in this array, and we'll # put in the table headings first my @tbl_rows = ( th( ['File', 'Word', 'Count'] ) ); for my $digit (0 .. 9) { for my $file (<$digit*>) { open (my $FILE_HANDLE, '<', $file) || die "Can't open $file: $! \n +"; while (<$FILE_HANDLE>) { chomp; my ($word, $count) = split / /, $_; if ($word =~ /^$search_term$/) { # Next, we'll convert your print statement: #print "At $file $word had $count points.", p; # into code to store a row of data into the array: push @tbl_rows, td( [$file, $word, $count] ); } } close ($FILE_HANDLE); } } # Then turn the rows into a table. (I'm quite unsure of # the syntax, so you'll have to adjust it as required.) print table( Tr( \@tbl_rows ) );

Does this help you go in the right direction?

[1] The part I looked at was just under the heading THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS. Frankly, I was surprised CGI was even installed on my machine! I guess it's part of the core distribution, the cygwin distribution, a requirement of another package I installed from CPAN or I just selected *all* perl modules available, or similar.

...roboticus


In reply to Re^3: cgi table by roboticus
in thread cgi table by frenchface

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, details, 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, summary, 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.