Comments in the code:


indicate that ports should be matched to servers, i.e. indeed be iterated together.

The increment at

looks indeed to be much too late, what with the two `continue`s at

and


Moving the increment just after

should work

The proposed nested iteration will not match servers and ports as documented. It would try each port with each server, i.e do a cartesian product of both, like a SQL join.

However

    foreach server  $options(-servers) $port $options(-ports) { ... }

might do what we want, if it fills missing elements with the empty string when on of the lists is too short.

That would avoid all the index calculations entirely.