Deleting a section of file using perl

A

Ami

Hi All,
I am reading and file and same time modifying it (Inline edit). I
store a particular position of file on some criteria using tell() and
than after reading some other stuff, i need to decide, if i want to
delete the contents of file from previously stored position till
current position.
It would be great help, if some one can give me idea/code snippet to
do it.
I need a code to delete file contents from one position to another
position and again continue processing file in same way.

Thanks in advance for your help.
Regards,
 
M

Mumia W.

Hi All,
I am reading and file and same time modifying it (Inline edit). I
store a particular position of file on some criteria using tell() and
than after reading some other stuff, i need to decide, if i want to
delete the contents of file from previously stored position till
current position.
It would be great help, if some one can give me idea/code snippet to
do it.
I need a code to delete file contents from one position to another
position and again continue processing file in same way.

Thanks in advance for your help.
Regards,

Inline editing doesn't mix too well with seek() and tell(), so you'll
probably have to redesign the program to not use inline editing.

If you have a line-oriented file, Tie::File is a great way to make a
file look like an array of lines; you can then use array operations on
that file and delete groups of lines at will.
 
X

xhoster

Ami said:
Hi All,
I am reading and file and same time modifying it (Inline edit).

By that do you mean -i (or $^I) ?
I
store a particular position of file on some criteria using tell() and
than after reading some other stuff, i need to decide, if i want to
delete the contents of file from previously stored position till
current position.

Can you just delay printing that chunk, storing it in memory instead,
until you make that decision? Then either print it or discard it. If you
can't do it this way, rather than with tell or whatever, then I think that
trying to use -i is a mistake.
It would be great help, if some one can give me idea/code snippet to
do it.
I need a code to delete file contents from one position to another
position and again continue processing file in same way.

See the implementation of Tie::File. It is not easy, and will probably
be slower than molasses.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
A

Ami

By that do you mean -i (or $^I) ?


Can you just delay printing that chunk, storing it in memory instead,
until you make that decision? Then either print it or discard it. If you
can't do it this way, rather than with tell or whatever, then I think that
trying to use -i is a mistake.


See the implementation of Tie::File. It is not easy, and will probably
be slower than molasses.

Xho

--
--------------------http://NewsReader.Com/--------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Hi All,
Thanks for your response. I have opted to go for using another
output file and keeping track of what part of file is needed to be
truncated. By using this method, i can serve my purpose.
Regards,
 

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
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top