![]() |
|
laziness, impatience, and hubris | |
PerlMonks |
Re^5: What's the right way to write a method which returns one line at a time from a file?by Tux (Abbot) |
on Nov 23, 2020 at 07:57 UTC ( #11124054=note: print w/replies, xml ) | Need Help?? |
It is not what is executed in the else block, but what is execute after.
If statement (1) exits the enclosing scope with return/exit/die/croak, statement (3) is never executed. An if/else is the to do something different based on a condition and then continue doing what is after the construct for all cases. This implies that an else immediately after return/exit/die/croak is always useless. The original code does it right in the first block:
Which - when following the wrong method you approve of - would be
In my way, the second block should be reduced to
That last return is arguable anyway, as the readline method can be a method that legally can return undef, "", and 0 (or any object evaluating as false) indicating that the original code was wrong to start with. Enjoy, Have FUN! H.Merijn
In Section
Seekers of Perl Wisdom
|
|