LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2008, 07:24 AM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
how to erase contents in a file in perl


IN perl, is there a way to to erase the contents of a text file after reading it.
 
Old 04-04-2008, 08:19 AM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
Rewrite the file?

What about closing the file, and then opening it for write with no append?
 
Old 04-04-2008, 09:53 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Code:
perldoc -f truncate
 
Old 04-04-2008, 02:57 PM   #4
prad77
Member
 
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
if we open the file with > symbol then it will Truncate (erase) the contents before writing.

open( FILEHANDLE, ">filename.txt" ) or die "filename.txt: $!";

Otherwise,
If you are using BASH as a shell, run this:
echo -n > file

Other shells will use:
echo 'c' > file

Gentoo

Last edited by prad77; 04-17-2008 at 03:41 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unauthorised file erase pingvina Linux - Software 28 02-21-2006 12:28 PM
erase all the lines of a file Prasun1 Linux - General 9 11-06-2005 10:53 AM
erase file ust Linux - General 1 03-10-2005 08:46 AM
Probleme to erase a file os2 Programming 2 02-15-2005 03:17 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration