<br>
Platform is perl 5.005.03 on AIX 4.1.5.<br>
<br>
I wrote a for loop incorrectly and it almost worked, which caused me some grief. Why does this loop exit?<br>
<br>
I meant to write <br>
for ($sl = length($s), $sl < $l, $sl = length($s)) {<br>
<br>
but what I wrote was<br>
<br>
$s = "12345678";<br>
$l = 14;<br>
for ($sl = length($s), $sl < $l,) {<br>
$s .= $s; # double the length of $s<br>
}<br>
$s = substr($s, 0, $l);<br>
<br>
The intent is to create a string of length $l, starting from some arbitrary string. As written, the loop always runs twice, then exits. That is correct behavior as long as the initial length of $s is more than 1/2 $l and less than $l. But if any of those values change then the loop still runs twice then exits. Why?<br>
<br>
<br>
( I know, I really should have just written<br>
while (length($s) < $l) { $s .=$s }<br>
<br>
I must have been more tired than usual that day. But the question still remains, why does the malformed for loop exit? )<br>
<br>
Thanks!<br>
- Kai.<br>
Platform is perl 5.005.03 on AIX 4.1.5.<br>
<br>
I wrote a for loop incorrectly and it almost worked, which caused me some grief. Why does this loop exit?<br>
<br>
I meant to write <br>
for ($sl = length($s), $sl < $l, $sl = length($s)) {<br>
<br>
but what I wrote was<br>
<br>
$s = "12345678";<br>
$l = 14;<br>
for ($sl = length($s), $sl < $l,) {<br>
$s .= $s; # double the length of $s<br>
}<br>
$s = substr($s, 0, $l);<br>
<br>
The intent is to create a string of length $l, starting from some arbitrary string. As written, the loop always runs twice, then exits. That is correct behavior as long as the initial length of $s is more than 1/2 $l and less than $l. But if any of those values change then the loop still runs twice then exits. Why?<br>
<br>
<br>
( I know, I really should have just written<br>
while (length($s) < $l) { $s .=$s }<br>
<br>
I must have been more tired than usual that day. But the question still remains, why does the malformed for loop exit? )<br>
<br>
Thanks!<br>
- Kai.<br>