|Think about Loose Coupling|
Re: How to "transfer control" to child process?by John M. Dlugosz (Monsignor)
|on May 23, 2011 at 20:09 UTC||Need Help??|
I have some comments on the script itself, even though that's not what you were posting about.
I already mentioned use strict; use warnings. But also, what version of Perl are you using? If it is reasonably up to date, you can use the new "given/when" construct.
You are not declaring your variables. This will be caught by strict, and mis-spelled variables is one of the easiest mistakes to make and find automatically.
You are using explicit variable name in constructs that use $_ implicitly, but still using $_ for the variable. If you are going to use a name, use a named local variable. Or if you use $_, leave it off. For serious programming (as opposed to quick one liners or one-time-use scripts) you use the explicit form as you did, but use a name.
You don't need the parens around the condition in the suffix (statement modifier) form. I don't see where @configFile is coming from. It will be empty! So there might be stuff you're not showing in the example.
Now the cool up-to-date stuff. If you use Perl 5.10 or higher, you can use given/when. But, that works with a foreach as well, so I'll revert to using the implicit $_ form:
Now the use of split splits on whitespace, but you already went through the string with the regexp and found the space. So use the results of the regexp instead of splitting again:
Note that you are requiring a space after the colon and before the name. If that is an artefact of your use of the simple split, you don't need that this way. Change the + to a * if you like.
Note finally that [0-9] is common enough to have an optimized abbreviation: \d for digit.
The stuff for Step is rather convoluted. In the same mold that I just showed, try:
But there is really no reason to note the $tag in these lines, as it was just a byproduct of your use of split. This limits you to 10 steps (0 through 9) as single digits. If you used \d+ it would be open ended.
But your following loop starts at 1, not zero. So even though you accept a step 0, you never use it.
There's really no need to specify the "number of steps". Just use whatever is in the array when you've read it: