Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: overwriting a file

by Sidhekin (Priest)
on Oct 30, 2007 at 11:15 UTC ( #647998=note: print w/ replies, xml ) Need Help??


in reply to overwriting a file

As long as you open the file with mode >, the old contents should be gone already.

Assuming you are opening with mode +>, +< or similar (for read/seek/write combos, particularly useful with file locking), this is a real problem, and the solution you are looking for is truncate, probably with tell:

truncate( OPENFILE, tell(OPENFILE) );

(Alternatively, if you can safely truncate to 0 before you even start writing, that might be clearer.)

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!


Comment on Re: overwriting a file
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (15)
As of 2015-07-06 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls