How can this be happening? Perl says 7 > 21 ?? 
Author Message
 How can this be happening? Perl says 7 > 21 ??

Below is a simple script that shows the problem I am having, followed by the
output from the script.  Why does Perl think 7 > 21 and 9 > 25?  Of course
Perl doesn't really think this, and I am doing something wrong.  But I can't
figure out what.  Please help!

#!/usr/bin/perl
$username="username" ;
$password="password" ;
$myhash{$username}=21 ;
$myhash{$password}=25 ;
print "username max length=$myhash{$username};password max
length=$myhash{$password}\n" ;
$username_from_user="joedirt" ;
$password_from_user="something" ;
print "length of \"$username_from_user\"=" . length($username_from_user) ;
print "; length of \"$password_from_user\"=" . length($password_from_user) .
"\n" ;
if (length($username_from_user) gt $myhash{$username}) {
    print "Username is too long: " .
    length($username_from_user) . " > " . $myhash{$username} . "\n" ;

Quote:
}

if (length($password_from_user) gt $myhash{$password}) {
    print "Password is too long: " .
    length($password_from_user) . " > " . $myhash{$password} . "\n" ;

Quote:
}

OUTPUT:
# ./test.pl
username max length=21;password max length=25
length of "joedirt"=7; length of "something"=9
Username is too long: 7 > 21
Password is too long: 9 > 25

-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
    http://www.*-*-*.com/       The Largest Usenet Servers in the World!
------== Over 100,000 Newsgroups - Ulimited downloads - 19 servers ==-----



Thu, 23 Sep 2004 23:34:17 GMT  
 How can this be happening? Perl says 7 > 21 ??

Quote:

> Below is a simple script that shows the problem I am having, followed by the
> output from the script.  Why does Perl think 7 > 21 and 9 > 25?  Of course
> Perl doesn't really think this, and I am doing something wrong.  But I can't
> figure out what.  Please help!

Do you know the difference between gt and > ?


#!/usr/bin/env perl

use strict;
use warnings;

my $length1 = 7;
my $length2 = 21;

if ($length1 gt $length2) {
   print "$length1 gt $length2\n";

Quote:
}

if ($length1 > $length2) {
   print "$length1 > $length2\n";
Quote:
}


7 gt 21

The first character of '7' is "stringwise" greater than the first character of
'21'.  Perl's warnings can alert you when you use something non numeric as
one of the values for a numeric comparison, but '7' and '21' are perfectly
reasonable strings.

Look at the Relational Operators section in the perlop man page.

Hope this helps,

Mike

--

http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA

http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA



Thu, 23 Sep 2004 23:48:49 GMT  
 How can this be happening? Perl says 7 > 21 ??

Quote:

> Do you know the difference between gt and > ?

I guess that would be a 'no'!

Quote:
> Look at the Relational Operators section in the perlop man page.

Will do.  Thank you!


Quote:

> > Below is a simple script that shows the problem I am having, followed by
the
> > output from the script.  Why does Perl think 7 > 21 and 9 > 25?  Of
course
> > Perl doesn't really think this, and I am doing something wrong.  But I
can't
> > figure out what.  Please help!

> Do you know the difference between gt and > ?


> #!/usr/bin/env perl

> use strict;
> use warnings;

> my $length1 = 7;
> my $length2 = 21;

> if ($length1 gt $length2) {
>    print "$length1 gt $length2\n";
> }

> if ($length1 > $length2) {
>    print "$length1 > $length2\n";
> }

> 7 gt 21

> The first character of '7' is "stringwise" greater than the first
character of
> '21'.  Perl's warnings can alert you when you use something non numeric as
> one of the values for a numeric comparison, but '7' and '21' are perfectly
> reasonable strings.

> Look at the Relational Operators section in the perlop man page.

> Hope this helps,

> Mike

> --

apply.
> http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA

3D60
> http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599

13DA

-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 100,000 Newsgroups - Ulimited downloads - 19 servers ==-----



Fri, 24 Sep 2004 00:00:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. install libwww-perl-5.21

2. Perl tutorials at U Penn on Monday April 14 and April 21

3. perl 4.0 patch #21

4. perl 3.0 patch #21

5. Examples from TY Perl in 21 Days

6. ANNOUNCE: Perl tut # 21 - How to use XML::XQL - xmlSplitter.pl

7. bug report: Archive::Tar-0.21 in perl 5.6.0 on i686 RHL6.1

8. ANN: Phila Area Perl Training, 17-21 Aug

9. click submit ->starts downloading perl file......dont want it to happen

10. Wanted: DBD::SQLite-0.21 for Win32 (5.6.1)

11. ANNOUNCE: Net::LDAPapi v1.21 Available

 

 
Powered by phpBB® Forum Software