********** July 3rd and July 5th colors.cgi PERL code ********** #!/usr/bin/perl -w use CGI qw(:standard); srand; @colors1 = qw(Red Green Blue Black Purple Yellow White Pink Orange Brown); @colors2 = qw(Blue Yellow Yellow White Yellow Purple Black Black Black Pink); if (param()) { $recently = param('recentcolors'); @c = split (/:/, $recently); do { $whichColor = int (rand(@colors1)); $repeat = 0; for ($i=0; $i<@c; $i++) { if ($whichColor == $c[$i]) { $repeat = 1; } } } while ($repeat == 1); unshift (@c, $whichColor); if (@c > 4) { pop @c; } $recentColors = join(":", @c); } else { $whichColor = int (rand(@colors1)); $recentColors = $whichColor; } # if ($whichColor == 3 || $whichColor == 9) NOT NEEDED # { $textColor = "White"; } USING color2 array # elsif ($whichColor == 4) for TEXT color that # { $textColor = "Yellow"; } is good contrast and # else match with BGCOLOR # { $textColor = "Black"; } from color1 array... print header, start_html(-title => "Color $colors1[$whichColor]", -BGCOLOR => "$colors1[$whichColor]", -TEXT => "$colors2[$whichColor]"), h1("This is background color $colors1[$whichColor] " . "and text color $colors2[$whichColor]"), start_form, "", submit('Random Color'), end_form; print end_html;