Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

lt versus le in string comparision

by Len (Friar)
on Jun 13, 2002 at 13:47 UTC ( [id://174190]=perlquestion: print w/replies, xml ) Need Help??

Len has asked for the wisdom of the Perl Monks concerning the following question: (strings)

Can anyone explain me this:
$char = 'a'; while ($char lt 'z') { print $char; $char++; }
prints as expected the characters (a..y) but if I change lt in le in the while expression:
while ( $char le 'z' )
it prints (a..yz) instead of the expected (a..z)

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: lt versus le in string comparision
by Abigail-II (Bishop) on Jun 13, 2002 at 14:06 UTC
    Consider this:
    my $str = 'y'; $str ++; print "$str\n"; $str ++; print "$str\n";
    This will print
        z
        aa
    
    Now, both z and aa are less or equal to z. It isn't until you reach za that you have a string that isn't less or equal to z.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://174190]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found