note
LanX
<ul>
<LI> Case1: you're resetting $i each time at the beginning
<LI> Case3 the $i scoped within the block is differentš from the outer one <br>(update: and you are resetting the inner one each time again)
</ul><P><P>
Generally better use prefix-constructs like<P><P>
<c>while () {...} </c>, <c>until () {...} </c> or <c> for (;;) {...}</c><P><P>
e.g. Case 3:
<c>
use strict;
use warnings;
my $i=42;
print "outside: $i\n";
for (my $i=5; $i>0; $i--) {
print "inside: $i\n";
};
print "outside: $i\n";
my $j=666;
print "outside: $j\n";
{ my $j=5;
do {
print"inside: $j\n";
$j--;
} until($j<=0)
}
print "outside: $j\n";
</c> <P><P>
prints:
<c>
outside: 42
inside: 5
inside: 4
inside: 3
inside: 2
inside: 1
outside: 42
outside: 666
inside: 5
inside: 4
inside: 3
inside: 2
inside: 1
outside: 666
</c><P><P>
As you can see, does the postfix construction force you to an extra block to limit the scope of the inner $j.<P><P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf
<p> <small>( addicted to the Perl Programming Language) </small>
</div></div><P><P>
<H5> Update<P></H5><P>
expanded code example<P><P>
<H5> Footnotes</H5>
1) see [http://perl.plover.com/FAQs/Namespaces.html|Coping with Scoping]
1033998
1033998