Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: How to read every 16 line of file ?

by ikegami (Patriarch)
on May 13, 2011 at 02:42 UTC ( #904578=note: print w/replies, xml ) Need Help??

in reply to How to read every 16 line of file ?

while (<>) { say if $. % 16 == 0; }

$., %

Replies are listed 'Best First'.
Re^2: How to read every 16 line of file ?
by tchrist (Pilgrim) on May 13, 2011 at 03:12 UTC
    You forgot to reset line numbers across file boundaries.
      FWIW, if reading from STDIN, there are no file boundaries :)

        My code reads from ARGV, not STDIN, so his comment does apply. Mind you, the OP said "file" singular, so resetting shouldn't be necessary.

        See eof to reset the counter between files when using ARGV.

        This is my sample code to be execute but this is sample only..
        #!/usr/bin/perl -w open (FILE, "/tmp/test.txt"); while ($line = <FILE>) { ... READ EVERY 16 LINE... } close(FILE);

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://904578]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-03-22 09:23 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.