...or more legibly

I think you might be obscuring the wood with a lot of trees there! Perhaps use of the -n switch would be applicable here, either in a script or as a one-liner.

$ cat rubbish Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line8 Line9 Line10 Line11 Line12 $ perl -ne 'print if 2 .. 7;' rubbish Line2 Line3 Line4 Line5 Line6 Line7 $

The array slice method is, as you say, only suitable for small files whereas using -n when combined with last is more efficient when interested only in lines at the beginning of large files. The following examples were acting on a 2,000,000+ line log file.

# time perl -ne 'print if 5 .. 10' maillog Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... real 0m1.206s user 0m0.773s sys 0m0.432s # time perl -ne 'print if 5 .. 10; last if $. > 10' maillog Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... real 0m0.013s user 0m0.006s sys 0m0.008s #

I hope this is of interest.

Cheers,

JohnGG


In reply to Re^3: regex issue by johngg
in thread regex issue by pinnacle

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.