in reply to Re^6: Radoteur
in thread Radoteur

In simple and obvious code I agree, but right now I am trying to educate myself so I can work on intricate code without making a mess.

Actually, “intricate” code is a mess, almost by definition! Putting performance to one side for the moment, the best way to avoid writing spaghetti code1 is by keeping things as clear and simple as possible. Structured programming was first proposed precisely for this reason; and the Perl next and last commands violate the (original) structured programming maxim that every loop have only a single entry point and a single exit point.

Does this mean you should avoid next and last when programming Perl? No, they’re too useful — and, when used judiciously, they actually make the programming logic clearer (to a seasoned Perl programmer, anyway). But when nested loops begin to intertwine their control flow, spaghetti code is likely to be the result. And the need for multiple loop labels is a strong warning sign that control flow may have become too complicated.

So, by all means use labels on loops when it makes sense to do so. But please don’t assume that doing so equates to “ease of maintenance” — it may all-too-easily lead to the exact opposite.

1Also called write-only code, since it is unmaintainable.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,