[tpm] Fast(er) way of deleting X lines from start of a file

Madison Kelly linux at alteeve.com
Thu Oct 1 08:53:46 PDT 2009


Uri Guttman wrote:
>>>>>> "MK" == Madison Kelly <linux at alteeve.com> writes:
> 
>   MK> Hi all,
>   MK>   Thus far, I've opened a file, read it in, shifted/ignored the first
>   MK> X number of line and then wrote out the resulting file. This works,
>   MK> but strikes me as horribly inefficient. Doubly so when the file could
>   MK> be larger than RAM.
> 
>   MK>   So then, is there a more efficient/faster way of saying "Delete the
>   MK> first X number of lines from file foo"?
> 
> this is a file system problem, not a perl one. the file system (other
> than on things like vms) doesn't allow deleting from the front of the
> file. it has to be copied in and out with the edits being done on the
> fly. there are many perlish ways to do this including tie::file, reading
> line by line and printing but ignoring the early lines using $. and
> slurping in the whole file (file::slurp::read_file) into an array,
> splicing off the lines and printing it out again (with
> file::slurp::write_file).
> 
> uri

Hrm, I wasn't thinking about this at the file system level. I wonder 
then if shell tools will in fact be any faster than pure-perl 
implementations if they all need to read in -> write out the full file 
behind the scenes.

Thanks for the datapoint!

Madi



More information about the toronto-pm mailing list