in reply to Reading Text Lines
The basic idea is to have the number of the first line that you want to display and use $. to work out where you are in the file.
my $page = 1; # which page to display my $display_perl_page = 100; my $first = ($page - 1) * $display_perl_page; my $last = $first + $display_perl_page; while (<VIEWFILE>) { next unless $. >= $first; last if $. > $last; # display this record }
(That code is untested, there may be an off-by-one error)
There are modules like Data::Page that make this all a lot easier.
Another alternative might be Tie::File.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading Text Lines
by Fletch (Bishop) on May 11, 2006 at 16:54 UTC |