Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to Delete File Contents

Reply
Thread Tools

How to Delete File Contents

 
 
newzguy
Guest
Posts: n/a
 
      08-07-2004
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
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      08-07-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (newzguy) wrote in news:6d7814d4.0408061938.3856e8a4
@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
 
Reply With Quote
 
 
 
 
Scott W Gifford
Guest
Posts: n/a
 
      08-07-2004
(E-Mail Removed) (newzguy) writes:

> 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.
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      08-07-2004
newzguy wrote:
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
J2ME allow to delete contents of a file jen Java 0 03-10-2011 03:41 AM
Adding contents on yaml file without overwriting actual contents Kamarulnizam Rahim Ruby 4 01-28-2011 09:10 AM
Can I restrict both attribute contents and element contents in schema Don Adams XML 1 03-05-2004 12:48 PM
delete contents of text file Poppy ASP .Net 6 02-11-2004 04:34 PM



Advertisments