#!/perl/bin/perl use CGI qw(:standard); use strict; my @fields = qw(title actors desc aprt price id category); my $page = (param("pg") > 1) ? (param("pg") - 1) : 0; my $limit = 9; my $start = $page * $limit; my $finish = $start + $limit - 1; my @files = (); opendir (DIR, "data") or die $!; @files = sort grep {/\.txt$/} readdir(DIR); closedir (DIR); print header(), start_html(); for ($start .. $finish) { if (defined $files[$_]) { my $file = $files[$_]; open (TXT, "data/$file") or die "couldn't open file $_: $!"; while () { my %rec; chomp; @rec{@fields} = split /\|/; print qq|Title=$rec{title}|; print "
"; } close (TXT); } } if ($start > 0) { my $prev = param("pg") - 1; print qq|prev |; } if (defined $files[$finish + 1]) { my $next = param("pg") + 1; print qq|next|; } print end_html();