You picked my least favorite example of all the ideas presented here. (In fact, I voted it down as being harmful advice.) That is checking each element to see if it exactly matches the ONE element which needs a break following (
$mech eq "3"). It's very inflexible:
- if you need to change where the newline happens, you have to edit the loop code,
- if you change your data, you have to edit the loop code,
- if you need more than one newline, you have to edit the loop code,
- if your data has more than one such element, you have to edit the loop code,
- and so on.
Good algorithms work in terms of the most general solution, so that you don't have to keep going in there and changing the code. Every change to the code means another chance of getting it wrong, more testing and debugging, and being hit by a bug later which testing didn't find.
--
[ e d @ h a l l e y . c c ]