Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Cleaning out a text file.

Reply
Thread Tools

Cleaning out a text file.

 
 
Avatar
Guest
Posts: n/a
 
      07-15-2003
I am trying to just open a file and clear it. Is there an easier way
to do this than the way I have done.

open (DELETE, ">$filename");
print DELETE "";
close DELETE;
 
Reply With Quote
 
 
 
 
Peter Wilson
Guest
Posts: n/a
 
      07-15-2003
"Avatar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I am trying to just open a file and clear it. Is there an easier way
> to do this than the way I have done.
>
> open (DELETE, ">$filename");
> print DELETE "";
> close DELETE;


Why not just unlink it?

Peter


 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      07-15-2003
>>>>> "TC" == Tony Curtis <(E-Mail Removed)> writes:

>>> open (DELETE, ">$filename");
>>> print DELETE "";
>>> close DELETE;


>> Why not just unlink it?


TC> Well, it's possible that the file needs to remain in
TC> existence, but be empty.

TC> The OP should just open for write and close immediately
TC> (and check the success of the open() too).

perldoc -f truncate

or unlink and utime will do it.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      07-15-2003
Uri Guttman wrote:
>>>>>> "TC" == Tony Curtis <(E-Mail Removed)> writes:

>
> >>> open (DELETE, ">$filename");
> >>> print DELETE "";
> >>> close DELETE;

>
> >> Why not just unlink it?

>
>> Well, it's possible that the file needs to remain in
>> existence, but be empty.

>
>> The OP should just open for write and close immediately
>> (and check the success of the open() too).

>
> perldoc -f truncate
>
> or unlink and utime will do it.


Careful! If you unlink the file then only this directoy entry will be
removed. If there are several hard links pointing to the same file, then
maybe the OPs intention was to actually empty this original file.
Unlink will actually remove the entry and when re-creating a file with the
same name it will be a new file that is not related to the old file any
longer, i.e. the other hardlinks will still point to the old file.

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
Cleaning out cache History Fan Firefox 5 11-16-2005 09:34 AM
Cleaning out stored images and pics?? Eddie Computer Support 5 04-22-2005 03:31 PM
Cleaning Out Registry. Patrick D. Rockwell Computer Support 30 05-16-2004 06:42 AM
Cleaning out Windows Temp Folder rfdjr1@optonline.net Computer Support 32 10-16-2003 08:47 PM
Cleaning out the garbage Haveajellybaby Computer Support 5 06-26-2003 02:23 PM



Advertisments