skydesigns
Technical User
Hello!
I'm working on a script for creating static html pages from a mysql db. I have a working version that creates a separate page for each record and one index file, which contains chosen fields from each record and a link to the detail page for each record.
The problem is that my db is quite large, and I would like to have multiple index pages with say - 50 links per page. I'm fairly new at Perl and can't figure our how to do this.
I would appreciate any ideas!
Here's my working script so far (excluding variables, etc.):
&connectdb;
open (TEMPL, $templ);
undef ($/);
$template=<TEMPL>;
close TEMPL;
open (TEMPL, $index_templ);
undef ($/);
$index_template=<TEMPL>;
close TEMPL;
($top, $record, $bottom)=split(/<!--record-->/, $index_template);
mkdir ($dir, 0777);
chmod($dir, 0777);
$index_file="$dir/$index_file";
$index_text_page=$top;
while ($h = $sth->fetchrow_hashref) {
%item = %{$h};
# Here we create the detail pages for each record
$line=$template;
$line=~s/\{\{([^\}]+)\}\}/$item{$1}/g;
$file="$dir/$item{login}.shtml";
open(FILE, ">$file"
chmod ($file, 0666);
print FILE $line;
close FILE;
# Here we create the index page for all records - I would like to make multiple indexes, with 50 or so records per index page
$link="$item{login}.shtml";
$line=$record;
$line=~s/!link!/$link/;
$line=~s/\{\{([^\}]+)\}\}/$item{$1}/g;
$index_text_page.=$line;
}
$index_text_page.=$bottom;
open(FILE, ">$index_file"
chmod ($index_file, 0666);
print FILE $index_text_page;
close FILE;
I'm working on a script for creating static html pages from a mysql db. I have a working version that creates a separate page for each record and one index file, which contains chosen fields from each record and a link to the detail page for each record.
The problem is that my db is quite large, and I would like to have multiple index pages with say - 50 links per page. I'm fairly new at Perl and can't figure our how to do this.
I would appreciate any ideas!
Here's my working script so far (excluding variables, etc.):
&connectdb;
open (TEMPL, $templ);
undef ($/);
$template=<TEMPL>;
close TEMPL;
open (TEMPL, $index_templ);
undef ($/);
$index_template=<TEMPL>;
close TEMPL;
($top, $record, $bottom)=split(/<!--record-->/, $index_template);
mkdir ($dir, 0777);
chmod($dir, 0777);
$index_file="$dir/$index_file";
$index_text_page=$top;
while ($h = $sth->fetchrow_hashref) {
%item = %{$h};
# Here we create the detail pages for each record
$line=$template;
$line=~s/\{\{([^\}]+)\}\}/$item{$1}/g;
$file="$dir/$item{login}.shtml";
open(FILE, ">$file"
chmod ($file, 0666);
print FILE $line;
close FILE;
# Here we create the index page for all records - I would like to make multiple indexes, with 50 or so records per index page
$link="$item{login}.shtml";
$line=$record;
$line=~s/!link!/$link/;
$line=~s/\{\{([^\}]+)\}\}/$item{$1}/g;
$index_text_page.=$line;
}
$index_text_page.=$bottom;
open(FILE, ">$index_file"
chmod ($index_file, 0666);
print FILE $index_text_page;
close FILE;