Hi Magne, On Tuesday 13 Apr 2010 06:35:51 Magne Sandøy wrote: > Hi. > > I'm new to perl, and I stumbled across a strange behavior in my for loop. > In the following code, the second for loop actually counts way passed > what I expected, and actually stops at "yz" and not "z" as expected. > As shown by the third for loop, incrementing the letters, seems to give > me the desired output in each loop. > What is going on here? > > > #!/usr/bin/perl > use warnings; > use strict; > > my $letter = "u"; > > for ("u".."z"){ > print " $_ "; > } > > print "\n\n"; > > for ($_="u"; $_ le "z"; $_++){ > print " $_ "; > }
"le" is the string equivalent of "<=" (less than or equal). You probably want "lt" instead here. A program using it yields the following: {{ u v w x y z u v w x y u v w x y z aa }} Regards, Shlomi Fish > > print "\n\n"; > > for(1..7){ > print " $letter "; > $letter++; > } -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Freecell Solver - http://fc-solve.berlios.de/ Deletionists delete Wikipedia articles that they consider lame. Chuck Norris deletes deletionists whom he considers lame. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/