$/ to read 100 lines at a time

cog on 2004-04-30T16:44:36

If I wanted to read X lines at a time (say 100), how should I do that using $/ ?

Some regex with a look behind to find 100 \n's would do the trick, probably... but isn't there an easier way? :-|


Uh, no.

Mr. Muskrat on 2004-04-30T17:52:03

From perlvar:
Remember: the value of $/ is a string, not a regex. awk has to be better for something. :-)

Inline

mary.poppins on 2004-04-30T19:12:59

Using Inline::C, of course! :)

Don't do too much work

brian_d_foy on 2004-04-30T21:18:22

Instead of something complicated, just write a routine that reads the right number of lines and returns them.
my @lines = read_lines( $fh, 100 );
That routine can be as simple as a for() loop. Once you code those five or six lines, relax, put your feet up on the table, and get on with life. :)

Re:Don't do too much work

cog on 2004-05-05T11:48:36

What do you mean, five or six lines? :-)

while (@_ = map eof() ? () : scalar , 1..$n) { # ... }

Courtesy of the guys from the FWP list :-)