Hi all,
I've got a problem in a Perl CGI script that I'm writing (running WinXP), where it tries to check the validity of user input to see if certain field values have the allowed range of 1 to 10. However the script doesn't work properly. I added some debugging stuff to it, to show what users entered and what the program processed:
The output from not_valid() is '7'
In HEX: 0x0
Is '7' bigger than '5'? NO
Is '7' less than '20'? YES
The QUERY_STRING that was sent by the browser was:
test_cgi.pl?name=SIMON&email=SIMON&q1=7&q2=6&q2a=None.&q3=8&q4=7&q5=9&q6=None.&q7=7&comments=None.
The place where I think the problem is, is the function not_valid(), where it actually checks the thing. Here's the snippet of code for it:
sub not_valid() {
$n = shift;
# Debug: Here's basically the problem
print "<p>The output from <code>not_valid()</code> is ", $n, "</p>\n";
print "<p>In HEX: <code>0x", hex($n), "</code></p>\n\n";
print "<p>Is $n bigger than \'5\'? ";
if (($n gt "5") || ($n gt '5') || ($n > '5')) {
print "YES</p>\n\n";
if ($n gt "5") {
print "<p>YES by string comparison (WHAT???)</p>\n\n";
}
elsif ($n gt '5') {
print "<p>YES by string \'\' comparison (WHAT???)</p>",
"\n\n";
}
else {
print "<p>YES by numerical comparsion \'>\' using " .
"ASCII equivalent of 5 (SHIT!)</p>\n\n";
}
}
else {
print "NO</p>\n\n";
}
print "<p>Is $n less than \'20\'? ";
if (($n lt "20") || ($n lt '20') || ($n < '20')) {
print "YES</p>\n\n";
}
else {
print "NO</p>\n\n";
}
# End of Debug
if (($n > 0) && ($n < 11)) {
return 0;
}
else {
return 1;
}
}
Any help would be great. I've been stuck on this prob for some time, and I've tried asking in #perl chat rooms on IRC, but to no avail.
Thanks alot,
Simon Liu
I've got a problem in a Perl CGI script that I'm writing (running WinXP), where it tries to check the validity of user input to see if certain field values have the allowed range of 1 to 10. However the script doesn't work properly. I added some debugging stuff to it, to show what users entered and what the program processed:
The output from not_valid() is '7'
In HEX: 0x0
Is '7' bigger than '5'? NO
Is '7' less than '20'? YES
The QUERY_STRING that was sent by the browser was:
test_cgi.pl?name=SIMON&email=SIMON&q1=7&q2=6&q2a=None.&q3=8&q4=7&q5=9&q6=None.&q7=7&comments=None.
The place where I think the problem is, is the function not_valid(), where it actually checks the thing. Here's the snippet of code for it:
sub not_valid() {
$n = shift;
# Debug: Here's basically the problem
print "<p>The output from <code>not_valid()</code> is ", $n, "</p>\n";
print "<p>In HEX: <code>0x", hex($n), "</code></p>\n\n";
print "<p>Is $n bigger than \'5\'? ";
if (($n gt "5") || ($n gt '5') || ($n > '5')) {
print "YES</p>\n\n";
if ($n gt "5") {
print "<p>YES by string comparison (WHAT???)</p>\n\n";
}
elsif ($n gt '5') {
print "<p>YES by string \'\' comparison (WHAT???)</p>",
"\n\n";
}
else {
print "<p>YES by numerical comparsion \'>\' using " .
"ASCII equivalent of 5 (SHIT!)</p>\n\n";
}
}
else {
print "NO</p>\n\n";
}
print "<p>Is $n less than \'20\'? ";
if (($n lt "20") || ($n lt '20') || ($n < '20')) {
print "YES</p>\n\n";
}
else {
print "NO</p>\n\n";
}
# End of Debug
if (($n > 0) && ($n < 11)) {
return 0;
}
else {
return 1;
}
}
Any help would be great. I've been stuck on this prob for some time, and I've tried asking in #perl chat rooms on IRC, but to no avail.
Thanks alot,
Simon Liu