P
prelim_questions
I have only a couple weeks of experience with Perl. In that time, I
figured out how to put together a prototype CGI application. But at
times, I had to resort to writing bad code, because I did not know how
to do certain things in Perl.
How do I turn the following into a loop or otherwise make it much
easier to write?
if (param("pick") eq "$quiz11[4]"){
system("/home/username/script option1 option2 \"$quiz11[4]\" ");
print redirect("http:my_url");
} elsif (param("pick") eq "$quiz11[3]"){
system("/home/username/script option1 option2 \"$quiz11[3]\" ");
print redirect("http:my_url");
} elsif (param("pick") eq "$quiz11[2]"){
system("/home/username/script option1 option2 \"$quiz11[2]\" ");
print redirect("http:my_url");
} elsif (param("pick") eq "$quiz11[1]"){
system("/home/username/script option1 option2 \"$quiz11[1]\" ");
print redirect("http:my_url");
}
So in this example, $quiz11 has 4 elements, hence 4 conditionals and
in general would have number of conditionals equal to number of
elements. Also, within a given block of code like this, the URL, the
script, and the option1 and option2 do not change.
Thanks in advance... I am trying to learn as much as I can!
figured out how to put together a prototype CGI application. But at
times, I had to resort to writing bad code, because I did not know how
to do certain things in Perl.
How do I turn the following into a loop or otherwise make it much
easier to write?
if (param("pick") eq "$quiz11[4]"){
system("/home/username/script option1 option2 \"$quiz11[4]\" ");
print redirect("http:my_url");
} elsif (param("pick") eq "$quiz11[3]"){
system("/home/username/script option1 option2 \"$quiz11[3]\" ");
print redirect("http:my_url");
} elsif (param("pick") eq "$quiz11[2]"){
system("/home/username/script option1 option2 \"$quiz11[2]\" ");
print redirect("http:my_url");
} elsif (param("pick") eq "$quiz11[1]"){
system("/home/username/script option1 option2 \"$quiz11[1]\" ");
print redirect("http:my_url");
}
So in this example, $quiz11 has 4 elements, hence 4 conditionals and
in general would have number of conditionals equal to number of
elements. Also, within a given block of code like this, the URL, the
script, and the option1 and option2 do not change.
Thanks in advance... I am trying to learn as much as I can!