Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Zeroing A File

by ptum (Priest)
on Mar 17, 2006 at 21:09 UTC ( #537578=note: print w/replies, xml ) Need Help??


in reply to Zeroing A File

Update: (added a little more code)

You might consider:

use strict; my $file = '/tmp/this_file'; my $fh; unless (open($fh,">$file")) { die "I can't open $file for writing: $!"; } truncate $fh, 0; close($fh);

Of course, this example is a little contrived, since if you open the file for writing like that and then close it, I think it will truncate it without needing the truncate command. But I can conceive of using that truncate() command if I had been writing to a file and then decided to start over. I must admit, I have never used it.

Another update: Ah, as pointed out by bluto, the truncate command also can be called in the form:

truncate $myfile, 0;

... which is at least somewhat more useful.

If the file is not owned by you, then you may need to have group- or world- writable permissions set on it, depending on your operating system.


No good deed goes unpunished. -- (attributed to) Oscar Wilde

Replies are listed 'Best First'.
Re^2: Zeroing A File
by tc1364 (Beadle) on Mar 17, 2006 at 21:51 UTC
    thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-01-22 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (60 votes). Check out past polls.

    Notices?