Owen wrote:
On Tue, 13 Apr 2010 05:35:51 +0200
Magne Sandøy <msan...@gmail.com> 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 " $_ ";
}
In the above, when $_ gets to 'y' it is less than 'z' so it
auto increments to 'z', then when the next comparison is made, it is
equal to 'z' and so increments again.
At which point it becomes "aa", which is less than or equal to "z". It
is not until it becomes "za" is it greater than "z".
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/