in reply to Re: Handling multiple output files simultaneously using arrays of filehandles and filenames
in thread Handling multiple output files simultaneously using arrays of filehandles and filenames

A stylistic advice reference is Perl Best Practices, Chapter 10 (I/O), Item 136: Always put filehandles in braces within any print statement:

It's easy to lose a lexical filehandle that's being used in the argument list of a print:

print $file $name, $rank, $serial_num, "\n";

Putting braces around the filehandle helps it stand out clearly:

print {$file} $name, $rank, $serial_num, "\n";
The braces also convey your intentions regarding that variable; namely that you really did mean it to be treated as a filehandle, and just didn't forget a comma.

An alternative syntax using IO::Handle:

use IO::Handle; $file->print( $name, $rank, $serial_num, "\n" );

  • Comment on Re^2: Handling multiple output files simultaneously using arrays of filehandles and filenames
  • Select or Download Code