in reply to Inertion sort in perl
...because in a string comparison, '2' is not less than '10' (comparison happens character-wise, and '2' is not smaller than '1' (ascii-betically))
my $n = 10; for my $i (1..$n) { printf "'%s lt %s' is %s\n", $i, $n, $i lt $n ? "true":"false"; } __END__ '1 lt 10' is true '2 lt 10' is false '3 lt 10' is false '4 lt 10' is false '5 lt 10' is false '6 lt 10' is false '7 lt 10' is false '8 lt 10' is false '9 lt 10' is false '10 lt 10' is false
(Tip: change $n to 11 in the above snippet and note that '10 lt 11' is true in contrast to most others...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Insertion sort in perl
by AnomalousMonk (Archbishop) on Apr 25, 2009 at 13:26 UTC |