in reply to Re: Skipping the first 4 lines of a file:: Is there a better way?
in thread Skipping the first 4 lines of a file:: Is there a better way?

Efficiency aside, does this really work? Okay, well, I know the answer: it doesn't. There is no limit on the split, and the delimiter is any {4} lines.

So, if my file is 10 lines long, I get two empty strings, then the remaining 2 lines. Infact, you only ever end up with the last X lines of your file (where X = lines % $skip), preceeded with (lines div $skip) empty strings.

@_ = split /(?:.+\n){$skip}/m, "@_", 2; # add limit # closer, but now I have @_ == 2, # since there is a leading null shift @_; # now I have a single element array with # the file remainder in $_[0] @_ = split /\n/, $_[0]; # now I have the desired results.

I agree that solutions don't always need to be the most efficient, but parsing through the entire file at least three times is O(n) where O(1) is available in a single line of code.

  • Comment on Re^2: Skipping the first 4 lines of a file:: Is there a better way?
  • Download Code