- 论坛徽章:
- 0
|
原代码如下:#!C:/Perl/bin/perl.exe -w
这个代码是我从一本书中打下来的。
目的是为了学习如何掌握隐含信息,如何使用窗口。
但是为什么当我点击第一页的submit后,并不能打开第二页呢?
请大家帮助解答。
use strict;
use Fcntl qw(:flock);
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
my $surveyfile="/tmp/survey.txt";
my @survey_answers=qw(pettype daytype clothes
castaway travel risky ownpet
realname comments);
my $semaphore_file="/tmp/survey.sem";
print header;
if(! param){
page_one();
}elsif(defined param('pageone')){
page_two();
}elsif(defined param('pagetwo')){
page_three();
}else{
survey_done();
}
sub page_one{
print "test";
print<<END_PAGE_ONE;
<FORM>
Are you a "cat person" or a "dog person"?<BR>
<INPUT type=radio name=pettype value=dog>Dog<BR>
<INPUT type=radio name=pettype value=cat>Cat<BR>
<P>
Are you more of an early-riser or a night owl?<BR>
<INPUT type=radio name=daytype value=earl>Early riser<BR>
<INPUT type=radio name=daytype value=late>Night owl<BR>
<P>
At work, if you had a choice on how to dress....<BR>
<INPUT type=radio name=clothes value=casual>Casual<BR>
<INPUT type=radio name=clothes value=business>Business<BR>
<P>
If stranded on a desert island,
who would you rather be stuck with?<BR>
<INPUT type=radio name=castway value=ginger>Ginger<BR>
<INPUT type=radio name=castway value=marya>Mary-Anne<BR>
<INPUT type=radio name=castway value=prof>Professor<BR>
<INPUT type=radio name=castway value=skipper>Skipper<BR>
<INPUT type=submit name=pageone value="Next page">
</FORM>
END_PAGE_ONE
}
#
sub repeat_hidden{
print "test";
foreach my $answer(@survey_answers){
if(defined param($answer)){
print "<INPUT TYPE=hidden";
print "name=$answer";
print " value=\"",param($answer),"\">\n";
}
}
}
sub page_two{
my $pet=param('pettype');
if(!defined $pet){
$pet="goldfish";
}
print<<END_PAGE_TWO;
<FORM>
Would you rather...<BR>
<INPUTtype=radio name=travel value=travel>Travel<BR>
<INPUT type=radio name=travel value=home>Stay at home<BR>
<P>
Do you consider yourself...<BR>
<INPUT type=radio name=risky value=yes>A daredevi<BR>
<INPUT type=radio name=risky value=no>Cautions<BR>
<P>
Do you own a $pet?<BR>
<INPUT type=radio name=ownpet value=$pet>Yes<BR>
<INPUT type=radio name=ownpet value=no>No<BR>
<P>
<INPUT TYPE=submit name=pagetwo value="Last Page">
END_PAGE_TWO
repeat_hidden();
print "</FORM>";
}
sub page_three{
print "test";
print<<END_PAGE_THREE;
<FORM>
last page! This information is optional!<BR>
Your name:
<INPUT TYPE=text name="realname"><BR>
Any comments about this survey:<BR>
<TEXTARE NAME=comments cols=40 rows=10>
</TEXTAREA>
<P>
<INPUT type=submit name=pagethree
value="submit survey results">
END_PAGE_THREE
repeat_hidden();
print "</FORM>";
}
sub survey_done{
save();
print "Thanks You!";
}
#
# Save all of the survey results to $surveyfile
#
sub save{
get_lock();
open(SF,">>$surveyfile")||die "Cannot open $surveyfile: $!";
foreach my $answer(@survey_answers){
if (defined param ($answer)){
print SF $answer,"-,param($answer)","\n";
}
}
close(SF);
release_lock();
}
#
#Locks and Unlocks the survey file so that multiple survey-takers
#Don't clash and write at the same time.
#
#Function to lock(watis indefinitely)
sub get_lock{
open(SEM,">$semaphore_file")
||die "Cannot create semaphore:$!";
flock SEM, LOCK_EX;
}
#
sub release_lock{
close(SEM);
}
[[i] 本帖最后由 生物信息学 于 2009-9-2 23:33 编辑 [/i]] |
|