Why does this not work?
am 15.01.2006 19:31:32 von FJRussonc
I am turning to you who might have had this problem before:
$Lz = length $FORM{'fname'}; <--- comes up with the corrrect length of the
string
If ( $Lz gt 7 ) <-- here is where the problem is. It passes to the return
and not into the code section when the length is > 7 -- WHY??
{
# code section here
}
return;
Ideas anyone?
Frank
NC
Re: Why does this not work?
am 15.01.2006 19:49:48 von Lactarius
In normal time if ( x gt y) is use for comparaison of STRING type. Try if
( $Lz > 7) may be it's better.
Lactarius.
"Frank J. Russo" a écrit dans le message de news:
8ywyf.7842$ZA2.6713@newsread1.news.atl.earthlink.net...
>I am turning to you who might have had this problem before:
>
> $Lz = length $FORM{'fname'}; <--- comes up with the corrrect length of
> the string
> If ( $Lz gt 7 ) <-- here is where the problem is. It passes to the
> return and not into the code section when the length is > 7 -- WHY??
> {
> # code section here
> }
> return;
>
> Ideas anyone?
>
> Frank
> NC
>
>
Re: Why does this not work?
am 15.01.2006 20:20:34 von Paul Lalli
Frank J. Russo wrote:
> I am turning to you who might have had this problem before:
>
> $Lz = length $FORM{'fname'};
Whenever I see $FORM in people's code I get nervous. If you are
running code to manually parse an HTTP query, please stop. Use the
standard CGI module which is almost certainly both more correct and
more robust than the solution you are using:
use CGI qw/:standard/;
my $Lz = length(param('fname'));
> <--- comes up with the corrrect length of the string
> If ( $Lz gt 7 ) <-- here is where the problem is. It passes to the return
> and not into the code section when the length is > 7 -- WHY??
Please read:
perldoc perlop
The operators gt, lt, ge, le, eq, ne, and cmp all operate on strings.
They compare their arguments according to each character's ASCII value.
If you want to compare operands numerically, use the operators >, <,
>=, <=, ==, !=, and <=>, respectively.
Some examples:
print "99 gt 100\n" if 99 gt 100;
print "99 lt 100\n" if 99 lt 100;
print "99 > 100\n" if 99 > 100;
print "99 < 100\n" if 99 < 100;
Slightly more amusing:
if ( 1 == 1.0) {
print "1 == 1.0\n";
} else {
print "1 != 1.0\n";
}
if ('1' eq '1.0' ) {
print "'1' eq '1.0'\n";
} else {
print "'1' ne '1.0'\n";
}
Paul Lalli