If I am writing a Perl script that overwrites STDERR with a duplicate of STDOUT but I never restore the filehandle, what happens at the end of script execution? I can't find anything that warns against what actually occurs or doesn't occur.
I'm probably misinformed but thanks for your patience.
A filehandle is a named internal Perl structure that associates a physical file with a name. All filehandles are capable of read/write access, so you can read from and update any file or device associated with a filehandle.
To close a file handle, and therefore disassociate the file handle from the corresponding file, you use the close function. This flushes the file handle's buffers and closes the system's file descriptor. If no FILEHANDLE is specified, then it closes the currently selected filehandle.
Perl open file function You use open() function to open files. The open() function has three arguments: Filehandle that associates with the file. Mode : you can open a file for reading, writing or appending.
When a process exits, the kernel recovers all used resources. This includes all the file descriptors, which are simply closed. If there is an application-level buffer, data in that buffer may not have been written to the kernel, but otherwise there is no risk in keeping file descriptors open before exiting.
If your Perl script ends by using exec
to launch another process, that process will inherit all the file descriptors (except those marked as close on exec).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With