Maybe this is not what you want. But why don't you open all of your FDs as "lexical FHs" (recommended in any case, IMHO) and push them into an @array. You can later
close $_ for @ARRAY if needed. (I prefer "lexical FHs" because they will automatically closed on scope exit
1 - I'm aware that sockets require an explicit
close, though.)
Update: incidentally
- The &-form of sub call is now obsolete and most likely not to do what one expects in most situations unless one really knows what he is doing.
- C-style for loops are legal, but are more error-prone and less reliable, not to say clear, than the corresponding perlish construncts.
1 Or more precisely when no more references exist.