On Wed, 28 Jan 2004, Jeff 'japhy' Pinyan wrote: > > When you read a line from a filehandle, Perl stores the line number in $., > so you can use that to your advantage: > > while (<FILE>) { > if ($. >= $start and $. <= $end) { > print; # or do whatever > } > } > > What's even better, though, is that there's another way to do that: > > while (<FILE>) { > if ($. == $start .. $. == $end) { > print; > } > } > > and if those values ($start and $end) are constants that are hard-coded > into your program, you can just write it as: > > while (<FILE>) { > if (10 .. 20) { > print; # displays lines 10 through 20 > } > } >
Wouldn't the following be slightly faster? while (<FILE>) { next if $. < $start; last if $. > $end; ... processing ... } the above example "aborts" reading the file once the last line has been read. -- Maranatha! John McKown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>