How to Delete File Contents

N

newzguy

How do I delete a file's content? I don't want it to
append, I want the contents overwritten, how do I
do it? What I have is:

# Append the fetched data to the local file.

open out, ">>$localfile";
print out $result->content;
close out;

Does the >> have something to do with appending?


thanks
 
A

A. Sinan Unur

(e-mail address removed) (newzguy) wrote in @posting.google.com:
How do I delete a file's content? I don't want it to
append, I want the contents overwritten, how do I
do it? What I have is:

# Append the fetched data to the local file.

open out, ">>$localfile";

open my $out, '>', $localfile or die "Cannot open $localfile: $!";
print out $result->content;
close out;

Does the >> have something to do with appending?

perldoc -f open
 
S

Scott W Gifford

How do I delete a file's content? I don't want it to
append, I want the contents overwritten, how do I
do it? What I have is:

# Append the fetched data to the local file.

open out, ">>$localfile";

Instead use

open out, ">$localfile";

See the documentation for open for more information.

----ScottG.
 
J

Jürgen Exner

newzguy said:
How do I delete a file's content?

Many different ways.
- you could delete the file and then recreate it; however coming to think of
it this would create new file although with the same file name.
- you could open the file for writing and immediately close it again
- ...
I don't want it to
append, I want the contents overwritten, how do I
do it? What I have is:

# Append the fetched data to the local file.

You don't want to append but you append?
Mind to explain?
open out, ">>$localfile";

Ok, you code comforms with the comment, but both of those conflict with your
spec.
print out $result->content;
close out;

Does the >> have something to do with appending?

What happened when you read the documentation for the open() function?

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top