in reply to •Re: On Foreach Loops and Maintainability
in thread On Foreach Loops and Maintainability
You could have written the original loop as:That was my first though, but on further reflection, it looks like configuration information (i.e., which form fields we're interested in) is getting mixed into the code. Is this a bad thing? Perhaps. If the fact that we're interested into "arg1" .. "arg5" (and might later be interested in "arg19" or "gee37") appears elsewhere in the code, then lifting that information out into a configuration section would make maintenance safer. my @formArgs = map { "arg$_" } 1..5; and then, later in the codefor (map("arg$_", 1..5)) { .. }
foreach ( @formArgs ) { .. }
|
|---|