LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-23-2006, 11:44 AM   #1
kurrupt
Member
 
Registered: Jul 2004
Distribution: Debian, Ubuntu, FreeBSD, RHEL
Posts: 202

Rep: Reputation: 31
perl CGI + dynamic table generation


I would like to create a randomly generated table by the user, the user will have the option to put x amount of cols and x mount of rows. once the user puts that in and submits it, i want the perl script to output that table with x cols and x rows

how would i make that possible?


Thanks!
 
Old 09-23-2006, 01:43 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
wow, thanks for the lengthy description of your situation. with all that info im sure you will get plenty of accurate answers.

maybe try to list what you have so far, for starters do you have a server with perl enabled? do you even know perl? do you know how to make forms in html? etc, etc, etc
 
Old 09-23-2006, 10:03 PM   #3
kurrupt
Member
 
Registered: Jul 2004
Distribution: Debian, Ubuntu, FreeBSD, RHEL
Posts: 202

Original Poster
Rep: Reputation: 31
yes, i know perl more or less, and yes i know how to make tables in html, and yes i have a server with perl enabled and its already running some scripts:

iam just looking for a general snippit of code to work with? more or less

Last edited by kurrupt; 09-23-2006 at 10:05 PM.
 
Old 09-23-2006, 10:04 PM   #4
kurrupt
Member
 
Registered: Jul 2004
Distribution: Debian, Ubuntu, FreeBSD, RHEL
Posts: 202

Original Poster
Rep: Reputation: 31
yes, i know perl more or less, and yes i know how to make tables in html, and yes i have a server with perl enabled and its already running some scripts:

iam just looking for a general snippit of code to work with? more or less

Eg:

Code:
HTML SIDE                                 |                    PERL SIDE OUTPUT TO BROWSER
---------                                 |                    ---------------------------
                                          | 
Please enter # of rows  [2]               |                ___  ___
Please enter # of cols  [2]               |                |   |   |
                                          |                |---|---|
Submit                                    |                |___|___|
 
Old 09-24-2006, 12:14 AM   #5
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by kurrupt
yes, i know perl more or less, and yes i know how to make tables in html, and yes i have a server with perl enabled and its already running some scripts:

iam just looking for a general snippit of code to work with? more or less
well its going to be more than a "snippit" of code. if you know perl and html and also have the server setup, i dont see what the problem is..

maybe someone else will want to write the program for you, but i dont.

(not trying to be a smartass (well maybe a little), but have you even attempted it?)
 
Old 09-24-2006, 01:05 AM   #6
kurrupt
Member
 
Registered: Jul 2004
Distribution: Debian, Ubuntu, FreeBSD, RHEL
Posts: 202

Original Poster
Rep: Reputation: 31
Yes i have, iam sorry i didnt paste it earlier. when i run it, it bascially goes into a loop and makes a trillion cols with 1 row.

but here it is:

Code:
#!/usr/bin/perl

use warnings;
use CGI;

my $cgi = new CGI;

# |------------------------------------------|
# | Here iam bringing over the paramaters    |
# | from the user input. Eg: col=5 ,row=5    |
# |------------------------------------------|

my $col = $cgi->param('col');
my $row = $cgi->param('row');

print   "Content-type\:text/html\n\n";

print "<html>";
print "<body>";





# |------------------------------------------|
# | Here i want to make a dynamic table from |
# | the user input x col, and x row          |
# |------------------------------------------|

print "<table border=1>";

while($row!=0){

  print "<tr>";

          while($col!=0) {

              print "<td>";

              print "testdata";

              print "</td>";

              $col--;
          }

print "</tr>";
$row--;

}

print "</table>";
print "</body>";
print "</html>";

Last edited by kurrupt; 09-24-2006 at 01:26 AM.
 
Old 09-27-2006, 11:04 PM   #7
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Rep: Reputation: 15
Do you know how make a formated webpage with your cgi script?
i am trying but keep getting server errors. I do not know any of the syntax, I am tryig to use other peoples code for a starters but I do not know where to begin.
I have a webpage that I want to calculate something with my script and create a formated webpage and print info on that page.

I am unable to even get the page to show up.
 
Old 09-27-2006, 11:22 PM   #8
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
kurrupt,

(sorry i forgot about you until circuit_girl posted..)

one problem is that you need to use some sort of temp variable in the loops, when you decrement col for the first row, none of the other rows will have any cols.

i dont see why it would be printing out a ton of columns though.. try a print when you get the cgi data, and make sure the col and row are what you think they are..
 
Old 09-27-2006, 11:25 PM   #9
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by circuit_girl
Do you know how make a formated webpage with your cgi script?
i am trying but keep getting server errors. I do not know any of the syntax, I am tryig to use other peoples code for a starters but I do not know where to begin.
I have a webpage that I want to calculate something with my script and create a formated webpage and print info on that page.

I am unable to even get the page to show up.
circuit_girl, it would probably be appropriate to start a new thread for your question. it would definately get more attention that way, your question might get lost in this thread..

also when you start that other thread, post the errors you get when you try the page. if you dont see any obvious errors, check the error log for your server.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 06:07 AM
Perl automatic page generation crazeinc Programming 4 09-21-2003 11:45 AM
Cultured Perl: Genetic algorithms, the next generation Debra Linux - Newbie 3 10-08-2002 06:14 PM
Cultured Perl: Genetic algorithms, the next generation Debra Linux - General 2 10-08-2002 04:26 PM
Cultured Perl: Genetic algorithms, the next generation Debra Programming 0 10-08-2002 03:59 PM


All times are GMT -5. The time now is 03:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration