Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I would like to close multiple open files handles.
Instead of:
$OUT1->close; $OUT2->close; $OUT3->close; $OUT4->close; $OUT5->close;
Is there is a simple 1 line of code or command to simply close them all at the same time?
Thanks.

Replies are listed 'Best First'.
Re: closing multiple filehandles with one command
by merlyn (Sage) on Aug 09, 2005 at 15:43 UTC
      As addition, because I see many numbered filehandles in some coworkers code:

      Or, if they're saved in a hash (which is imo the better way if you have no fixed or a large number of handles):
      # untested $hash{ $_ }->close for keys %hash;

      Ordinary morality is for ordinary people. -- Aleister Crowley
        A reply falls below the community's threshold of quality. You may see it by logging in.
      excellent....
      I don't know why I didn' think of that.
      Guess that's why you are the wizard and...
      I am still learning.
      Thanks!