open(DATA, "books.txt") or die "error opening file $!"; while () { @bookinfo = split(/\|/, $_); chomp(@bookinfo); if ($q{'lang'} eq '' || $bookinfo[1] eq $q{'lang'}) { $matchingwords=0; foreach $word(@search) { if ($_ =~ $word) { $matchBooks[$numMatches] = @bookinfo unless ($matchingwords>0); $numMatches++; $matchingwords++; } } } } if (@matchBooks>0) { my $sortby; if ($q{'sort'} eq 'author') {$sortby = 3;} else {$sortby = 2;} @matchBooks = sort {${$a}[$sortby] cmp ${$b}[$sortby]} @matchBooks; my $firstDis; my $lastDis; my $firstDisp; if ($q{'first'}) { $firstDis = $q{'first'}; $firstDisp = $q{'first'};} else { $firstDis = 1; $firstDisp = 1; } if ($firstDis + 9 < $numMatches) {$lastDis = $firstDis + 9;} else {$lastDis = $firstDis + ($numMatches - $firstDis);} $firstDisp = $firstDisp - 1; print 'Matching Books
'; print 'There are '.@matchBooks.' matches.
'; print "${firstDis}-${lastDis} are listed below.

"; print ""; while ($firstDisp < $lastDis) { ... }