We don't bite newbies here... much | |
PerlMonks |
Re: if-elsif-else (?)by GrandFather (Saint) |
on Jul 02, 2011 at 22:59 UTC ( [id://912506]=note: print w/replies, xml ) | Need Help?? |
Absolutely omit an "unused or useless" else clause. Including it adds clutter to your code making it harder to find the code that does real work and making it harder to see the decision tree that gets you to any particular outcome. With that in mind there is no need to add extra comments to say "Oh, and I really mean not to have some code here". Do you put a comment at the end of each line to say "This line is not conditional on anything"? The code structure itself should reflect thee intended behaviour. Relying on comments to make that clear will simply lead to trouble when the implementation and comment drift apart - perl doesn't read your comments. That said, it may be that a better implementation for your code could be something like:
or if the "line" numbers are important:
Whenever you catch yourself doing xx1 = ...; xx2 = ...; ... think instead about arrays and loops. It makes the code clearer and much much easier to maintain.
True laziness is hard work
In Section
Seekers of Perl Wisdom
|
|