Hi, there.
I'm a teacher from NY City. I have learned a very little bit of Perl. The teachers in my school love to play vocabulary BINGO with students. I'm trying to make our jobs easier by writing a simple script, but it's not so simple. I working on my knowledge of Perl, but I have hit a total roadblock.
I have written a small script that takes data (25 words) input by users from a form and then it spits out the words in the form of a table with borders to produce a bingo card. That part works fine.
Here's my dilemma, I then want a button to appear at the bottom that says something like, “Shuffle Words”. Then when the user clicks it, the script would create the same card with the words in a different order (random) within that table. Sounds simple, but I'm lost.
I'm on my fifth book that tells me anyone can write Perl, yet I still have no clue what to do. Could you please help?
A 1000 thanks!
Bob
Here is the code to the script, so far:
=====================================================================
#!/usr/bin/perl
# Decode incoming form data from browser
&parseForm;
# Print the page
&printPage;
## Begin sub routines #
# Decode and prepare form data
sub parseForm {
if ($ENV{'REQUEST_METHOD'} eq "POST"
{
read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
@pairs = split(/&/, $buffer);
} else {
@pairs = split(/&/,$ENV{'QUERY_STRING'});
}
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair, 2);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$in{$name} = $value;
}
$field1=$in{'word'};
$field2=$in{'word2'};
$field3=$in{'word3'};
$field4=$in{'word4'};
$field5=$in{'word5'};
$field6=$in{'word6'};
$field7=$in{'word7'};
$field8=$in{'word8'};
$field9=$in{'word9'};
$field10=$in{'word10'};
$field11=$in{'word11'};
$field12=$in{'word12'};
$field13=$in{'word13'};
$field14=$in{'word14'};
$field15=$in{'word15'};
$field16=$in{'word16'};
$field17=$in{'word17'};
$field18=$in{'word18'};
$field19=$in{'word19'};
$field20=$in{'word20'};
$field21=$in{'word21'};
$field22=$in{'word22'};
$field23=$in{'word23'};
$field24=$in{'word24'};
$field25=$in{'word25'};
}
# Print the page
sub printPage {
print "Content-type: text/html\n\n";
print<<"HTML";
<html>
<head>
<title>Your Bingo Card Is Ready!</title>
</head>
<body bgcolor="#FFFFFF">
<table width="620" border="5" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field1</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field6</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field11</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field16</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field21</font></b></font></div>
</td>
</tr>
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field2</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field7</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field12</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field17</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field22</font></b></font></div>
</td>
</tr>
<tr>
<td width="118" height="24">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field3</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122" height="24">
<div align="center"><font size="4"><b><font size="3">$field8</font></b></font></div>
</td>
<td width="127" height="24">
<div align="center"><font size="4"><b><font size="3">$field13</font></b></font></div>
</td>
<td width="120" height="24">
<div align="center"><font size="4"><b><font size="3">$field18</font></b></font></div>
</td>
<td width="113" height="24">
<div align="center"><font size="4"><b><font size="3">$field23</font></b></font></div>
</td>
</tr>
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field4</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field9</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field14</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field19</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field24</font></b></font></div>
</td>
</tr>
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field5</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field10</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field15</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field20</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field25</font></b></font></div>
</td>
</tr>
</table>
</body>
</html>
HTML
}
exit;
#END OF SCRIPT
I'm a teacher from NY City. I have learned a very little bit of Perl. The teachers in my school love to play vocabulary BINGO with students. I'm trying to make our jobs easier by writing a simple script, but it's not so simple. I working on my knowledge of Perl, but I have hit a total roadblock.
I have written a small script that takes data (25 words) input by users from a form and then it spits out the words in the form of a table with borders to produce a bingo card. That part works fine.
Here's my dilemma, I then want a button to appear at the bottom that says something like, “Shuffle Words”. Then when the user clicks it, the script would create the same card with the words in a different order (random) within that table. Sounds simple, but I'm lost.
I'm on my fifth book that tells me anyone can write Perl, yet I still have no clue what to do. Could you please help?
A 1000 thanks!
Bob
Here is the code to the script, so far:
=====================================================================
#!/usr/bin/perl
# Decode incoming form data from browser
&parseForm;
# Print the page
&printPage;
## Begin sub routines #
# Decode and prepare form data
sub parseForm {
if ($ENV{'REQUEST_METHOD'} eq "POST"
read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
@pairs = split(/&/, $buffer);
} else {
@pairs = split(/&/,$ENV{'QUERY_STRING'});
}
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair, 2);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$in{$name} = $value;
}
$field1=$in{'word'};
$field2=$in{'word2'};
$field3=$in{'word3'};
$field4=$in{'word4'};
$field5=$in{'word5'};
$field6=$in{'word6'};
$field7=$in{'word7'};
$field8=$in{'word8'};
$field9=$in{'word9'};
$field10=$in{'word10'};
$field11=$in{'word11'};
$field12=$in{'word12'};
$field13=$in{'word13'};
$field14=$in{'word14'};
$field15=$in{'word15'};
$field16=$in{'word16'};
$field17=$in{'word17'};
$field18=$in{'word18'};
$field19=$in{'word19'};
$field20=$in{'word20'};
$field21=$in{'word21'};
$field22=$in{'word22'};
$field23=$in{'word23'};
$field24=$in{'word24'};
$field25=$in{'word25'};
}
# Print the page
sub printPage {
print "Content-type: text/html\n\n";
print<<"HTML";
<html>
<head>
<title>Your Bingo Card Is Ready!</title>
</head>
<body bgcolor="#FFFFFF">
<table width="620" border="5" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field1</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field6</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field11</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field16</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field21</font></b></font></div>
</td>
</tr>
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field2</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field7</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field12</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field17</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field22</font></b></font></div>
</td>
</tr>
<tr>
<td width="118" height="24">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field3</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122" height="24">
<div align="center"><font size="4"><b><font size="3">$field8</font></b></font></div>
</td>
<td width="127" height="24">
<div align="center"><font size="4"><b><font size="3">$field13</font></b></font></div>
</td>
<td width="120" height="24">
<div align="center"><font size="4"><b><font size="3">$field18</font></b></font></div>
</td>
<td width="113" height="24">
<div align="center"><font size="4"><b><font size="3">$field23</font></b></font></div>
</td>
</tr>
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field4</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field9</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field14</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field19</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field24</font></b></font></div>
</td>
</tr>
<tr>
<td width="118">
<p align="center"> </p>
<p align="center"><font size="4"><b><font size="3">$field5</font></b></font></p>
<p align="center"> </p>
</td>
<td width="122">
<div align="center"><font size="4"><b><font size="3">$field10</font></b></font></div>
</td>
<td width="127">
<div align="center"><font size="4"><b><font size="3">$field15</font></b></font></div>
</td>
<td width="120">
<div align="center"><font size="4"><b><font size="3">$field20</font></b></font></div>
</td>
<td width="113">
<div align="center"><font size="4"><b><font size="3">$field25</font></b></font></div>
</td>
</tr>
</table>
</body>
</html>
HTML
}
exit;
#END OF SCRIPT