Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Passing file handle to tee that goes into open

by pjkang7 (Novice)
on Nov 09, 2016 at 22:43 UTC ( [id://1175633]=note: print w/replies, xml ) Need Help??


in reply to Re: Passing file handle to tee that goes into open
in thread Passing file handle to tee that goes into open

Oh yeah of course... I spent too much time trying to figure that out. I guess I will have to simply iterate of file handles. I wonder what will happen if I try to tee(append) directly to the file without closing the perl file handle for that file. Intuition tells me I shouldn't but yeah..

Thanks!

  • Comment on Re^2: Passing file handle to tee that goes into open

Replies are listed 'Best First'.
Re^3: Passing file handle to tee that goes into open
by johngg (Canon) on Nov 10, 2016 at 11:11 UTC

    If you have written to an open file handle in a Perl script the file pointer is at the end of the file. If you then append something to that file using an external program the file pointer in the Perl script is not updated and any subsequent writes in the script will overwrite the externally written data. Doing a seek to end of file in the script after the external program has completed should update the file pointer so that subsequent writes by the script continue after the external data.

    There may be better ways to write both internal and external data to the same file but I have used this technique without problems.

    Cheers,

    JohnGG

Re^3: Passing file handle to tee that goes into open
by stevieb (Canon) on Nov 09, 2016 at 23:11 UTC
    "I wonder what will happen if I try to tee(append) directly to the file without closing the perl file handle for that file. Intuition tells me I shouldn't..."

    Perhaps worthy of a test, but I'd go with your instinct here. You may introduce an issue in code that may work now, but when it goes awry later, you may be scratching your head as to wtf is happening... "it worked before!".

    I've never tried it to be honest, but doing things manually outside of an open file handle just can't be good :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1175633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found