CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
How do I dup() a filehandle in Perl?

 



Jasmine
Administrator

Jan 26, 2001, 10:40 AM

Post #1 of 1 (1940 views)
How do I dup() a filehandle in Perl? Can't Post

(From the Perl FAQ)

How do I dup() a filehandle in Perl?

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

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

Or even with a literal numeric descriptor:

Code
   $fd = $ENV{MHCONTEXTFD}; 
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.



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives