in reply to Re^2: cgi table
in thread cgi table

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

Replies are listed 'Best First'.
Re^4: cgi table
by frenchface (Initiate) on Sep 25, 2010 at 17:33 UTC
    That you so much for your reply. It is point me in the right direction. I'll explain a little more what I have. I have a script that is ran on an hourly bases. It downloads a text file from the internet. and saves it by the time it was download. They are in this format 9:00-Fri-Sep-24-2010.txt. In the text file there are two rows. THe first row is a name and the second row is a number. So my table I want to look like this

    0 1 2 3 4 5 6 7 8 9 10 11 12 13 ... 23 #where this is the time the fil +e was downloaded now here is going to be the data, each column is going to be all the d +ata for that time. the top will be the earilst and the bottom will be + the newest date. #so the whole thing will look like this 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ... 23 5 6 4 5 7 9 545 65 ... 4 5 4 3 424 45 35 1..
    also here is a snipet of what the txt files look like

    Kanes+Wrath 121 naffy123 136 Immortal+Hero 136 langers123x 120 Szundyyyyy 120 XfeverX 144 CaptainSalty 118 arhavin2 116 Layken 140 1Princess+Sparkle1 116
    Also when running the coded you provided I get the following output, which I am looking into the cause
    Global symbol "@tbl_rows" requires explicit package name at points2.cg +i line 35. Global symbol "@tbl_rows" requires explicit package name at points2.cg +i line 44. Execution of points2.cgi aborted due to compilation errors.

      frenchface:

      From the error message, it sounds like you didn't declare @tbl_rows. As far as your table description, I still don't understand it.

      ...roboticus

        Ok here is the best I can do.
        0 1 2 3 4 5 6 7 8 ...23 aug 1 aug 2 aug 3 aug 4 aug 5 etc
        So the top row will be the time the data was captured and the column is the date it was capture. Now like I said I have tons of txt files that are saved by the time and date. so if a person searches for "Doug" the script is going to search all of the text files for the name doug and print that in the table. when it opens up the file name 20:00-Fri-Sep-24-2010.txt it should place the data from the name Doug in the column 20 and the row Sep 24. So for one day there is 24 text files for each different hour of the day. Every different day is a different row in the chart. Again thanks for all your help, I hope this explains it so that you can understand it.