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

Uri Guttman uri at StemSystems.com
Wed Sep 30 08:53:58 PDT 2009


>>>>> "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

-- 
Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


More information about the toronto-pm mailing list