** Start of listing of h4int-perl.cgi ** #!/usr/bin/perl use CGI qw(:standard); print "Content-type: text/plain;charset=us-ascii\n\n"; # Check if string contains integer, possibly surrounded by whitespace. # Returns "" if OK, otherwise a string explaining the problem. sub strcheckint { my($str) = $_[0]; if ($str =~ m/^ *[-+]?[0-9]+ *$/) { return(""); # Good! } elsif (!($str =~ m/[0-9]+/)) { return("Not any digit anywhere."); } elsif ($str =~ m/^ *[-+][^0-9]+/) { return("Sign, but then no digit immediately."); } elsif ($str =~ m/^ *[-+]?[0-9]+.*[^ 0-9]+/) { return("Valid number, but then garbage later."); } elsif ($str =~ m/^ *[-+]?[0-9]+ *[^ ]+/) { return("Valid number, then whitespace, but then another digit."); } elsif ($str =~ m/^ *[^ 0-9]+.*[0-9]+/) { return("Garbage before the first digit."); } else { return("Stub: Something else bad."); } } sub keygetcheckint { my($key) = $_[0]; $fn = param($key); print("In form-field ["); print($key); print("] we have value ["); print($fn); print("]: "); my($res) = strcheckint($fn); if ($res =~ m/^$/) { # That should match empty string only $n = 0+$fn; print("Good! The number is ["); print($n); print("].\n"); print("The next larger numbers are: "); print($n+1); print(" "); print($n+2); print(" "); print($n+3); print("\n"); } else { print("Bad: "); print($res); print("\n"); } } keygetcheckint('num1'); keygetcheckint('num2'); keygetcheckint('num3'); keygetcheckint('num4'); keygetcheckint('num5'); keygetcheckint('num6'); keygetcheckint('num7'); keygetcheckint('num8'); #What's left of old test loop on stdio: #while (1) { # print("Type in a number:"); # $inputline = ; # print("You typed ["); print($inputline); print("].\n"); # chomp($inputline); # print("After trim, we now have ["); print($inputline); print("].\n"); # if(strcheckint($inputline)==0) { # } #} ** End of listing of h4int-perl.cgi ** Here is the directory entry for that file: -rwx------ 1 rem user 1924 Feb 28 2007 h4int-perl.cgi ^ Note user execute permission needed for all CGI scripts.