On Sat, 2002-04-27 at 08:53, Damian Conway wrote: > Which I presume was that the proposed usage: > > while $result.get_next() -> $next { > # do something with $next... > ELSE { > if $next eq "xyz572" { > print "We defined this value, $next, as false for obscure purposes."; > print "No loop was executed. Just wanted to let you know."; > } > } > } > > would actually be a (very subtle and nasty) bug!
I disagree. It has no bug (unless you want it to). I also thought while was gone, replaced by loop, but if while is in, then there's no bug. Here's the code, expanded: my $tmploop = sub ($next is rw) { # do something with $next... } my $tmpelse = sub ($next is rw) { print "We defined this value, $next, as false for obscure purposes."; } { my $tmpval; my $loopcnt = 0; loop { $tmpval = $result.get_next(); last unless $tmpval; $loopcnt++; $tmploop.($tmpval); } $tmpelse.($tmpval) unless $loopcnt; } Now, if you put the temporary inside of the loop scope, then I have to agree with you: there's no $next when you get to the else, but that's not the only way to do it, and I really don't think you SHOULD do it that way. After all, you might have important reasons to want access to that value! If you're implying that putting the else outside the block should indicate that $next is no longer in scope, I disagree on the exact same grounds. I want the else to be outside, but the primary reason to me is that it's far cleaner looking code. Is there any reason to do it the other way?