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.


In reply to Re^2: Skipping the first 4 lines of a file:: Is there a better way? by fishbot_v2
in thread Skipping the first 4 lines of a file:: Is there a better way? by PerlBear

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.