Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Homework question - passing private variables back and forth between two scrips

by linkperl (Initiate)
on Nov 28, 2005 at 01:20 UTC ( [id://512073]=perlquestion: print w/replies, xml ) Need Help??

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

This is a homework question. Had to write two scripts for homework. The first script presents a random math question that the user answers. The second scripts tells you the correct answer, if your answer is correct or incorrect, how many questions have been asked and answered correctly and the percent corrected. You can also click on two links to do another question or clear the counters and start again. Teacher wants the fields hidden between the two scripts and we cannot use a file. Successfully used a form to pass data from script 1 to script 2 and I'm able to pass variables at the end of the URL's from Script 2 to 1 but not hidden. Tired a form in script 2 but don't know how to suppress the boxes that appear. Here's script 1:

#! /usr/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; # generate the begining of the web page. + my $title = "CSGA 5030 Project 3: Arithmetic Drilling"; print header, "\n"; print start_html($title), "\n"; print h1($title), "\n"; #print <<EndHTML; + + my @ops = ("*", "/", "+", "-", "%"); my $c; my $a = int (rand(100)); my $b = int (rand(100)); my $op = $ops[int(rand(@ops))]; # make sure zero is not used for div ops + + if ($op == "/" || "%") { while ($b == 0 || $a == 0){ $b = int (rand(100)); $a = int (rand(100)); } }; eval '$c=$a' . $op . '$b'; my $roundc = int ($c); my $tqa; my $aca; # check to see if param has values else set counters to zero + + if (param()) { $tqa = param("totalQuestions"); $aca = param("answeredCorrectly"); } else { $tqa = 0; $aca = 0; } print <<EndHTML; <form action="answer" method="post"> <th>$a $op $b =</th> <input type="hidden" name="question" value="$a $op $b"> <input type="text" size="4" name="proposedAnswer"> <input type="hidden" name="trueAnswer" value="$roundc"> <input type="hidden" name="totalQuestions" value="$tqa"> <input type="hidden" name="answeredCorrectly" value="$aca"> <input type="submit" value="Check answer!"> <input type="reset" value="Clear"> </form> EndHTML

Script 2:

#! /usr/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; # generate the begining of the web page. + + my $title = "CSGA 5030 Project 3: Arithmetic Drilling"; my $qweb = "http://www.dsm.fordham.edu/~sheehan/cgi-bin/netwebprog-gra +d/proj3/question"; print header, "\n"; print start_html($title), "\n"; print h1($title), "\n"; my $question = param("question"); my $correctanswer = param("trueAnswer"); my $proposedans = param("proposedAnswer"); my $tq = param("totalQuestions"); my $ac = param("answeredCorrectly"); print "Question: $question\n"; print "Your answer: $proposedans\n"; print "True answer: $correctanswer\n"; print ""; ++$tq; # increment total number of questions asked if ($proposedans != $correctanswer){ print "<b>Incorrect!</b>\n"; }else { print "<b>Correct!</b>\n"; ++$ac; } my $percent = int(($ac/$tq)*100); print ""; print qq(<p>Score so far: $ac out of $tq ($percent percent) <p>\n); print qq(<a HREF="$qweb?totalQuestions=$tq&answeredCorrectly=$ac">Try +another problem</a>\n); print "\n"; print qq(<a HREF="$qweb?"input type = hidden" totalQuestions=0&answeredCorrectly=0">Start over with a clean slate</a +>\n);

Any advice would be greatly appreciated.

GrandFather changed \code tags to /code tags :)

Replies are listed 'Best First'.
Re: Homework question - passing private variables back and forth between two scrips
by planetscape (Chancellor) on Nov 28, 2005 at 01:31 UTC

    I wonder if a look at this might help...

    planetscape
Re: Homework question - passing private variables back and forth between two scrips
by JediWizard (Deacon) on Nov 28, 2005 at 02:10 UTC

    Cookies. CGI::Cookie


    They say that time changes things, but you actually have to change them yourself.

    —Andy Warhol

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://512073]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-18 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found