Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
laziness, impatience, and hubris
 
PerlMonks  

Re: duping a filehandle

by ikegami (Patriarch)
on Jan 13, 2007 at 22:58 UTC ( [id://594601]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to duping a filehandle

From the man page for dup (on FreeBSD):

The object referenced by the descriptor does not distinguish between oldd and newd in any way. Thus if newd and oldd are duplicate references to an open file, read(2), write(2) and lseek(2) calls all move a single pointer into the file, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional open(2) system call. The close-on- exec flag on the new file descriptor is unset.

(Emphasis mine)

Look into tell + seek instead of duping.

Replies are listed 'Best First'.
Re^2: duping a filehandle
by smackdab (Pilgrim) on Jan 14, 2007 at 00:02 UTC
    THANKS!!! I wish I knew unix better...I found a "seek($fh_log, 0, 0);" before returning from my subroutine put the filepointer back at the top, so all is good!
      Alternatively, pass just the filename to your sub and open it there using a different file handle (preferably lexical).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://594601]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.