CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Creating HTML from a script



Mar 12, 2001, 4:34 AM

Post #1 of 4 (505 views)
Creating HTML from a script Can't Post

Hi everyone,

I have been trying in vain for a long time to produce html from a perl script that produces an online quiz.

The way it is setup is that the script calls a header and a footer file which is fine, it then calls another file which prints the questions for the quiz in between the header and footer.

I have set up the header and footer to look like my site however I want to have the questions displayed inside a table that is centralised and has the same colours as the rest of my html page. Whenever I try to place the HTML into the script I receive error 500 message.

I have tried the print = there a special tag that is needed as the script does not seem to produce the <table> tag etc..

Any replies greatly received
Thanks again


Mar 12, 2001, 1:12 PM

Post #2 of 4 (494 views)
Re: Creating HTML from a script [In reply to] Can't Post

Try this:

print "<<EndOfHTML"; 
<table border="2">

Note that "EndOfHTML" is just a label; it could be any non reserved word. Also note that there is no semi-colon at the end of the closing label.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


Mar 12, 2001, 4:18 PM

Post #3 of 4 (489 views)
Re: Creating HTML from a script [In reply to] Can't Post

Hi thanks for the tips...

OK I have now got a page with the table and the word "working" in the middle...the next step is to take the following code which gathers and creates the questions on the page within the table instead of the word "working".

print "<center><form action=\"$url\" method=\"post\">\n";

open(CHOICES, $data_choices);
@choices = <CHOICES>;

open(QUES, $data_questions);
@questions = <QUES>;

for ($i=0; $i<$num_display; $i++) {
$sequence[$i] = -1;
for ($i=0; $i<$num_display; $i++) {
do {
$sequence[$i] = int(rand($num_questions));
$repeated = 0;
for ($j=0; $j<$num_display; $j++) {
if ($sequence[$i] == $sequence[$j] && $i != $j) {
$repeated = 1;
} while ($repeated == 1);

for ($i=0; $i<$num_display; $i++) {
print "<font face=\"verdana,geneva,arial\" size=2><b>";
print ($i+1);
print ". $questions[$sequence[$i]]</b></font>


print "<font face=\"verdana,geneva,arial\" size=2>";

if ($choices[$sequence[$i]] ne "") {
@temps = split(/\|/, $choices[$sequence[$i]]);
foreach $temp (@temps) {
print "<input type=\"radio\" name=\"$sequence[$i]\" value=\"$temp\">$temp ";
else {
print "Answer: <input type=\"text\" name=\"$sequence[$i]\" size=30>";

print "</font>\n";
print "<p>\n";

print "<font face=\"verdana,geneva,arial\" size=2>";
print "Please enter your alias: ";
print (defined($name)? "<input type=\"text\" name=\"name\" value=\"$name\">
\n": "<input type=\"text\" name=\"name\">
print "Please enter your E-mail: ";
print (defined($email)? "<input type=\"text\" name=\"email\" value=\"$email\">": "<input type=\"text\" name=\"email\">");
print "</font>\n<p>\n";

$" = "\|";

print <<END_OF_HTML;
<input type="hidden" name="action" value="submit">
<input type="hidden" name="number" value="$num_display">
<input type="hidden" name="sequence" value="@sequence">
<input type="submit" value="Grade Online Exam">


Phew....thanks again for any light you chaps can shed on this..its graetly appreciated.

User / Moderator

Mar 13, 2001, 8:06 PM

Post #4 of 4 (475 views)
Re: Creating HTML from a script [In reply to] Can't Post

You almost have it, but need to include some <tr> and <td> tags inside your big loop. Something like...

print "<tr><th>$index</th><td>\n$questions[$sequence[$i]]<p>\n$answer</td></tr>\n";

But while you are at it consider this alternative to find the sequence of questions to use...

my @availables = (1..$num_questions); 
my @sequence;
for (0..($num_display-1)) {
my $index = int(rand(scalar (@availables)));
push (@sequence, splice(@availables, $index, 1));

It makes a list of all the questions that can be used, and then one by one grabs randomly from it, deleting the used one so it can not be used again. Each statement will be executed $num_display times. In the original version you can start repeating frequently as $num_display approaches $num_questions.

PS. When you include blocks of code you can get it to appear as you really want it to if you include it inside &#091;pre&#093; &#091;/pre&#093;

Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives