in reply to Re^2: homemade blat: need help with reverse string.
in thread homemade blat: need help with reverse string.
Looking at just $length and $len, the code shown has the following content:
... my $len; my $sequenza; ... my $j; ... my $length = length($sequenza); ... print "Insert query:\n"; $query = <STDIN>; chomp $query; $len = length($query); ... for($j = $length; $j < $length - $len; $j--) { ... } ...
As you can see, when $length is initialized, $sequenza is undefined, so $length still has a numerical value of zero (as I pointed out above).
However, even if $length were to be initialized correctly before the for loop, the loop condition still looks wrong to me. $j is initially assigned the value in $length, and is then decremented on each iteration. The stopping condition is $j < $length - $len, and neither $length nor $len is changed in the loop body. So if the condition is initially true, i.e., if $j is initially less than some fixed value, decrementing $j will never make the condition false (well, not until an integer underflow occurs, anyway), which means you effectively have an infinite loop.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: homemade blat: need help with reverse string.
by nikkk (Novice) on Dec 19, 2015 at 16:51 UTC |