Deleting a section of file using perl
Deleting a section of file using perl
am 26.09.2007 09:24:45 von 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,
Re: Deleting a section of file using perl
am 26.09.2007 11:14:39 von paduille.4061.mumia.w+nospam
On 09/26/2007 02:24 AM, Ami wrote:
> 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.
Re: Deleting a section of file using perl
am 26.09.2007 18:08:34 von xhoster
Ami wrote:
> 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.
Re: Deleting a section of file using perl
am 27.09.2007 07:19:49 von AMI
On Sep 26, 9:08 pm, xhos...@gmail.com wrote:
> Ami wrote:
> > 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.
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,