Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

How do I dup() a filehandle in Perl?

by faq_monk (Initiate)
on Oct 13, 1999 at 03:42 UTC ( #815=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at

Here is our local, out-dated (pre-5.6) version:

If you check open, you'll see that several of the ways to call open() should do the trick. For example:

    open(LOG, ">>/tmp/logfile");
    open(STDERR, ">&LOG");

Or even with a literal numeric descriptor:

   open(MHCONTEXT, "<&=$fd");   # like fdopen(3S)

Note that ``<&STDIN'' makes a copy, but ``<&=STDIN'' make an alias. That means if you close an aliased handle, all aliases become inaccessible. This is not true with a copied one.

Error checking, as always, has been left as an exercise for the reader.

Log In?

What's my password?
Create A New User
erix counts their toes
[erix]: DBD::Pg 3.6.1 test has 'die;' then dies and fails wtf... (just below connect_database()
[erix]: I'm wondering what the idea could have been...
erix expletives

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-05-23 08:36 GMT
Find Nodes?
    Voting Booth?