CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
split pages

 



wickedxter
User

May 30, 2001, 4:50 PM

Post #1 of 3 (947 views)
split pages Can't Post

im stumped on how to split a file with more then 100+ entries.. and only display them like 20 at a time on one page and 20 on anouther page.

Any help would be nice.



Mortimer
journeyman

May 30, 2001, 5:53 PM

Post #2 of 3 (939 views)
Re: split pages [In reply to] Can't Post

Reading from a file with a format such as...

line1
line2
...
line32
line33
etc.

Just set $num_lines as required.

Code
use strict; 
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header;

my $prog_url = "http://domain/cgibin/nlines_per_page.cgi";
my $data_file = 'c:/path/to/data_file.txt';
my $num_lines = 20;
my(@lines);
my($start,$finish) = (0,$num_lines);

if( $q->param('next_lot') ne '' ){
($start,$finish) = split( '\|' , $q->param('next_lot') );
open(DATAF,"<$data_file")or die("Cannot open $data_file: $!");
while(<DATAF>){
if($. > $start && $. <= $finish){
push(@lines,$_);
}
}
$start = $finish;
$finish = $finish + $num_lines;
close(DATAF);
}

for(@lines){print "$_< br >";}
print "<a href=$prog_url?next_lot=$start|$finish>Next</a>";

Just polish it up a little and it should be a goer. You'll need to make the opening link
label something different from 'Next', and you'll probably want to reverse it somehow to
have a 'Previous' link. Note that the line break tag had to be bastardized for the requirements of this forum program.

Hope this helps.
Dave.
www.dmscripts.com
davemortimer@bigpond.com




wickedxter
User

May 30, 2001, 6:08 PM

Post #3 of 3 (935 views)
Re: split pages [In reply to] Can't Post

aww.... thx for the help..


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives