This is c04forandforeach.html
<?xml version="1.0"
encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml" lang="en"
xml:lang="en" dir="ltr">
<head>
<title>
For and
Foreach Example
</title>
<link rel="stylesheet"
type="text/css" href="http://abc/~webabc/cis47.css"/>
</head>
<body>
<h1>
Test of "for" loop
<br />
and "foreach" loop
</h1>
<form action="http://abc/~webabc/cgi-bin/c04forandforeach.cgi"
method="post" style="border: 7px outset
#fff;text-align:center;">
<h2>
For Input
</h2>
<table>
<tr>
<td>Number of loops<br />(must not be null)</td>
<td><input type="text" name="forloops"
size="1" value="1"></input></td>
</tr>
</table>
<h2>
Foreach
Input
</h2>
<table>
<tr>
<td><input type="checkbox" name="check"
value="1"></input>one</td>
<td><input type="checkbox" name="check"
value="2"></input>two</td>
<td><input type="checkbox" name="check"
value="3"></input>three</td>
<td><input type="checkbox"
name="check" value="4"></input>four</td>
<td><input type="checkbox" name="check"
value="5"></input>five</td>
<td><input type="checkbox" name="check"
value="6"></input>six</td>
</tr>
</table>
<p
style="text-align:center;">
<input
type="submit" value="Submit"></input>
<input
type="reset" value="Reset"></input>
</p>
</form>
<p
style="text-align:center;">
<a
href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31"
width="88" /></a>
<a
href="http://jigsaw.w3.org/css-validator/check/referer"><img
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" width="88" height="31"
/></a>
</p>
</body>
</html>
#!/usr/bin/perl
#c04forandforeach.cgi - week 2 for and foreach
example
#uses hash for param lookup
print "Content-type: text/html\n\n";
use CGI qw(:standard);
#Prevent unwanted variables
use strict;
#declare Variables
my ($loops, $foreach, $num, $key, @checked);
#assign values to variables
$loops=0;
$loops=param('forloops');
@checked=param('check');
#Load hash
my %foreachtext = ("1","one",
"2", "two",
"3", "three",
"4", "four",
"5", "five",
"6", "six");
#generate XHTML
print "<?xml version=\"1.0\"
encoding=\"iso-8859-1\"?>\n";
print "<!DOCTYPE html PUBLIC
\"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
print "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
print "<html
xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\"
xml:lang=\"en\" dir=\"ltr\">\n";
print "<head>\n";
print "
<title>\n";
print "
For and Foreach Demo\n";
print "
</title>\n";
print "<link rel=\"stylesheet\"
type=\"text/css\"
href=\"http://abc/~web07/cisabc.css\"/>\n";
print "</head>\n";
print "<body
style=\"text-align:center;font-size:120%;\">\n";
print "<h2>\n";
print "LOOPS Test Input was ", $loops,
" loops.\n";
print "</h2>\n";
#print "<p>\n";
for ($num=1; $num <= $loops; $num = $num + 1) {
print "loop # " , $num, "!<br
/>\n";
}
#print "</p>\n";
print "<h2>\n";
print "FOREACH Test\n";
print "</h2>\n";
print "<p>\n";
foreach $key(@checked)
{
print "Check box for " ,
$foreachtext{$key}, " was checked.<br />\n";
};
print "</p>\n";
print "<p>\n";
print "<a
href=\"http://validator.w3.org/check?uri=referer\">\n";
print "<img
src=\"http://www.w3.org/Icons/valid-xhtml10\"\n";
print "alt=\"Valid XHTML 1.0!\"
height=\"31\" width=\"88\" /></a>\n";
print "<a href=\"http://jigsaw.w3.org/css-validator/check/referer\">\n";
print "<img
src=\"http://jigsaw.w3.org/css-validator/images/vcss\"\n";
print "alt=\"Valid CSS!\"
width=\"88\" height=\"31\" /></a>\n";
print "</p>\n";
print "</body>\n";
print "</html>\n";
body
{
background-color:#ffffe0;
background-image:url("rlowellback.gif");
background-attachment:fixed;
font-family: "NewCenturySchlbk" ,
"Times New Roman" , Times , serif;
}
code
{
font-size:50%;
white-space:nowrap;
}
dt
{
font-weight:bold;
}
th
{
text-align:left;
}
.week
{
border: 7px inset #fff;
background-color: #ffffe0;
}
h1
{
text-align:center;
}