7.9.3. Discussion
Occasionally you have a file descriptor but no filehandle. Perl's I/O
system uses filehandles instead of file descriptors, so you have to
make a new filehandle from an already open file descriptor. The
"<&", ">&", and
"+<&" access modes to
open do this for reading, writing, and updating,
respectively. Adding an equals sign to these—making them
"<&=", ">&=", and
"+<&="—is more parsimonious of file
descriptors and nearly always what you want. That's because the
underlying implementation of Perl's open statement
uses only a C-level fdopen(3) function from the
C library, not a dup2(2) syscall that calls the
kernel.
The new_from_fd IO::Handle object method is
equivalent to:
use IO::Handle;
$fh = new IO::Handle;
$fh->fdopen($FDNUM, "r"); # open fd 3 for reading