Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am having trouble coding this cgi file, I have written up a full explanation on my webpage, if you would please have a look, I put up the sample data and what the table I am trying to get should look like. I will also include the html to my page but the you can't see the tables without going to my page, the site is:
http://www.geocities.com/skyodyssey/ <html> <head> </head> <body> Say I have this data: <br> I have more explanation at bottom of page <br><br> ACM Computing Surveys, InfoTrac, ExpAcd, Dec-96<br> ACM Computing Surveys, PDQ, ABIGlobal, Mar-96<br> ACM Computing Surveys, PDQ,PAbsII, Mar-96<br> ACM Transactions on Computer Systems, InfoTrac, ExpAcd,Nov-96<br> Communications of the ACM, InfoTrac, ExpAcd, Jan-89<br> Communications of the ACM, InfoTrac, GBus, Jan-88<br> Communications of the ACM, PDQ, ABIGlobal, Jan-92<br> Communications of the ACM, PDQ, PAbsII, Jan-92<br> <br> </center><p><br><center><table BORDER CELLSPACING=0 CELLPADDING=0 WIDT +H="100%" > <tr><td ALIGN=CENTER BGCOLOR="#C0C0C0">Journal</center></td><td ALIGN= +CENTER BGCOLOR="#C0C0C0">Resource</td><td ALIGN=CENTER BGCOLOR="#C0C0 +C0">Database</td><td ALIGN=CENTER BGCOLOR="#C0C0C0">Date</td></tr> <tr> <td rowspan=3 VALIGN=TOP>ACM Computing Surveys</td> <td rowspan=1>InfoTrac</td> <td>ExpAcd</td> <td>Dec-96</td> </tr> <tr> <td rowspan=2 >PQD</td> <td>ABIGlobal</td> <td rowspan=2 >Mar-96</td> </tr> <tr> <td>PAbsII</td> </tr> <tr> <td rowspan=1 VALIGN=TOP>ACM Transactions on Computer Systems</td> <td rowspan=1 >InfoTrac</td> <td>ExpAcd</td> <td>Nov-96</td> </tr> <tr> <td rowspan=4 VALIGN=TOP>Communications of the ACM</td> <td rowspan=2 >InfoTrac</td> <td>ExpAcd</td> <td>Jan-89</td> </tr> <tr> <td>GBus</td> <td>Jan-88</td> </tr> <tr> <td rowspan=2 >PQD</td> <td>ABIGlobal</td> <td rowspan=2 >Jan-92</td> </tr> <tr> <td>PAbsII</td> </tr> </table></center> <br> This is only a small portion of a large .csv file I will create. What + I be doing is searching the database I read in for a pattern given by the user then i will put into an array all the lines that matched, then I will +sort them and make a new array with all of the values split at the comma. what i wa +nt to do is is create a table like above, but note what I do when there are duplic +ate fields, I'm first looking at the first field, then I combine multiple fields withi +n that first field. It's easier to look at the table to see what i am trying to do. I har +d coded this table for the above sample data. Remember that I will not have a fixe +d amount of data. I am using a html page to send the keyword to my cgi, I have to use "use CG +I" to be able to get the parameters, problem is, I can't ever get "use HTML::Table" to +work, just includeing it make it crash, when i type perl -v i get version 5.005_03 built for + sun4-solaris, also i have to include this in my program <br> #!/usr/bin/perl -wT<br> print "Content-type:text/html\n\n";<br> <br> I hope this is enough info, I have been at this for days, and I can't +figure it out<br> Thanks for looking, any and all help will be appreciated!!!!!!!!!!!!!! +!!!!!!!!!!!!! </body> </html>
I have spent days at this, any help would be appreciated!!!! http://www.geocities.com/skyodyssey/

Replies are listed 'Best First'.
(jeffa) Re: printing a table in html using data read from a file
by jeffa (Bishop) on Jun 12, 2001 at 19:47 UTC
    You left out some pertinant info, so this may not be the EXACT answer you are looking for - but it works. I am only using CGI, i recommend using some CSV module for this, such as Text::CSV_XS or Text::xSV but since you are on another server and they obviously don't have the modules installed that you want, i present this to you:
    use strict; use CGI qw(:standard); print header(); print "<table>\n"; while (<DATA>) { chomp; print "\t<tr>\n"; print map { "\t\t<td>$_</td>\n" } split(/,/,$_); print "\t</tr>\n"; } print "</table>\n"; __DATA__ ACM Computing Surveys, InfoTrac, ExpAcd, Dec-96 ACM Computing Surveys, PDQ, ABIGlobal, Mar-96 ACM Computing Surveys, PDQ,PAbsII, Mar-96 ACM Transactions on Computer Systems, InfoTrac, ExpAcd,Nov-96 Communications of the ACM, InfoTrac, ExpAcd, Jan-89 Communications of the ACM, InfoTrac, GBus, Jan-88 Communications of the ACM, PDQ, ABIGlobal, Jan-92 Communications of the ACM, PDQ, PAbsII, Jan-92
    You will need to modify this to meet your needs, but at least it's a start. Have fun :)

    Also, you can always install modules on your personal space and use 'use lib' to let Perl know where to find them: use lib "/path/to/your/installed/mods";

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
Re: printing a table in html using data read from a file
by bikeNomad (Priest) on Jun 12, 2001 at 19:51 UTC
    There was a lot of good discussion about creating tables in this node (was that node by you too?). What stands out for me is your statement:
    I can't ever get "use HTML::Table" to work, just includeing it make it crash

    You might want to test your system by doing something simple like:

    #!/usr/bin/perl -wT use strict; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use CGI; use HTML::Table; print <<EOF Content-type: text/html\r \r <html><body><h1>Looks OK to me...</h1></body></html> EOF
    Then you should at least see if you can include HTML::Table. Look at the generated HTML as well; warnings will appear as HTML comments.
      This is what i get when I try your sample program I called it g.cgi:
      Software error: Can't continue after import errors at .../public_html/cgi-bin/g.cgi li +ne 3 BEGIN failed--compilation aborted at .../public_html/cgi-bin/g.c +gi line 3. For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error.
        It looks like you're missing CGI::Carp and/or HTML::Table in your installed modules. Make sure that you have them installed. Try running g.cgi from a command prompt:
        perl g.cgi
        .