ikegami really proposed the easiest solution; file line number (represented in $.), modulus 16. If there's no "remainder", you're on a line that is a multiple of 16. You could, as an alternative for math-challenged individuals, increment a counter, and when it gets to the trigger value reset it and print the line. But that's more work just for the sake of being lazy. ;)

Oh, that reminds me of why I replied to this post (after an obviously perfect answer has already been given)... You are asking how to read every 16th line, but you really should be asking how to ignore all but every 16th line. Or in other words, read every line but only take action on multiples of 16. There is no easy way to only read every 16th line, if lines are of unknown length. That's a little like asking how to find "steam" in the dictionary without thumbing through it to find it.

There is the other lazy and inefficient alternative of using Tie::File to gain an index to each line, but then you still have to do math, so it really doesn't buy you anything other than the ability to easily access any line at will.


Dave


In reply to Re: How to read every 16 line of file ? by davido
in thread How to read every 16 line of file ? by bh_perl

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.