Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Handling multiple output files simultaneously using arrays of filehandles and filenames

by eyepopslikeamosquito (Archbishop)
on Jan 22, 2021 at 01:09 UTC ( [id://11127253]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found