B
blnukem
Hi All
I use this script to update my website it is called via a second script that
uses strict. The problem is in the in the last routine "#Print the new web
page" section on the bottom the "foreach (@HtmlTemplate)" routine will only
process a "few" of the pages in the @MainLinks Array and then is stops. But
if I null out the entire "foreach (@HtmlTemplate)" routine and put print
"$HTMLPageData"; it will work fine but without the template data. I cant
seem to figure it out.
Thnaks in advance
blnukem
PERL CODE:
#!/usr/bin/perl -w
sub RebuildWebSite {
my ($DataBase,$PageType,$PageName,$LinkStatus);
######################################
# Get the master template
######################################
open (MASTERTEMPLATE,
"<$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat") ||
print "ERROR: Could not open MASTERTEMPLATE
$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat to read the
data: $!";
my @HtmlTemplate = <MASTERTEMPLATE>;
close(MASTERTEMPLATE);
######################################
# Read all of the sites pages into one array and reverse them
######################################
opendir (DIR,
"/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks")
|| print "ERROR: Cannot open directory: $!";
@ARGV = map
"/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks/$_"
, grep ! -d, readdir DIR;
closedir DIR;
@MainLinks = <>;
@MainLinks = reverse(@MainLinks);
print "@MainLinks"; #<-- For testing to make sure the array is complete.
foreach my $LinkName (@MainLinks) {
($DataBase,$PageType,$PageName,$LinkStatus) = split (/\|/, $LinkName);
$LinkStatus=~ s/\r//ig;
$LinkStatus =~ s/\n//ig;
######################################
# If the page is a blindlink skip it (for java menu).
######################################
if ($PageType eq "blindlink"){
next;
}
$LowercaseName = "$PageName";
$LowercaseName =~ s/\W//ig; # Remove all junk
$LowercaseName = lc($LowercaseName);
$HtmlPageToPrint = "$LowercaseName";
######################################
# We look for the index page
######################################
if ($PageType eq "index"){
$HtmlPageToPrint = "index";
}
######################################
# Get the text for the particular page in question
######################################
open (HTMLTEXT,
"<$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat") ||
print "ERROR: Could not open HTMLTEXT
$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat to read the
data: $!";
my @HtmlText = <HTMLTEXT>;
close(HTMLTEXT);
my $HTMLPageData = "@HtmlText"; #<-- $HTMLPageData is the varaible were
the text should go on the main template.
######################################
# Print the new web page #<-- Here is the trouble spot
######################################
open (HTLMLPAGE, ">$FolderPath/$HtmlPageToPrint.htm") || print "ERROR: Could
not open HTLMLPAGE $FolderPath/$HtmlPageToPrint.htm to print the data: $!";
foreach (@HtmlTemplate) {
my $xdata = $_;
$xdata =~ s/(\$\w+)/$1/eeg; # Process the variables
print HTLMLPAGE "$xdata";
}
close(HTLMLPAGE);
}# End of foreach
} # end of sub
1;
############# This also works fully but doesn't use template.
#
# #foreach (@HtmlTemplate) {
# #my $xdata = $_;
# #$xdata =~ s/(\$\w+)/$1/eeg; # Process the
variables
# #print HTLMLPAGE "$xdata";
# print HTLMLPAGE "$HTMLPageData";
# #}
# close(HTLMLPAGE);
I use this script to update my website it is called via a second script that
uses strict. The problem is in the in the last routine "#Print the new web
page" section on the bottom the "foreach (@HtmlTemplate)" routine will only
process a "few" of the pages in the @MainLinks Array and then is stops. But
if I null out the entire "foreach (@HtmlTemplate)" routine and put print
"$HTMLPageData"; it will work fine but without the template data. I cant
seem to figure it out.
Thnaks in advance
blnukem
PERL CODE:
#!/usr/bin/perl -w
sub RebuildWebSite {
my ($DataBase,$PageType,$PageName,$LinkStatus);
######################################
# Get the master template
######################################
open (MASTERTEMPLATE,
"<$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat") ||
print "ERROR: Could not open MASTERTEMPLATE
$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat to read the
data: $!";
my @HtmlTemplate = <MASTERTEMPLATE>;
close(MASTERTEMPLATE);
######################################
# Read all of the sites pages into one array and reverse them
######################################
opendir (DIR,
"/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks")
|| print "ERROR: Cannot open directory: $!";
@ARGV = map
"/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks/$_"
, grep ! -d, readdir DIR;
closedir DIR;
@MainLinks = <>;
@MainLinks = reverse(@MainLinks);
print "@MainLinks"; #<-- For testing to make sure the array is complete.
foreach my $LinkName (@MainLinks) {
($DataBase,$PageType,$PageName,$LinkStatus) = split (/\|/, $LinkName);
$LinkStatus=~ s/\r//ig;
$LinkStatus =~ s/\n//ig;
######################################
# If the page is a blindlink skip it (for java menu).
######################################
if ($PageType eq "blindlink"){
next;
}
$LowercaseName = "$PageName";
$LowercaseName =~ s/\W//ig; # Remove all junk
$LowercaseName = lc($LowercaseName);
$HtmlPageToPrint = "$LowercaseName";
######################################
# We look for the index page
######################################
if ($PageType eq "index"){
$HtmlPageToPrint = "index";
}
######################################
# Get the text for the particular page in question
######################################
open (HTMLTEXT,
"<$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat") ||
print "ERROR: Could not open HTMLTEXT
$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat to read the
data: $!";
my @HtmlText = <HTMLTEXT>;
close(HTMLTEXT);
my $HTMLPageData = "@HtmlText"; #<-- $HTMLPageData is the varaible were
the text should go on the main template.
######################################
# Print the new web page #<-- Here is the trouble spot
######################################
open (HTLMLPAGE, ">$FolderPath/$HtmlPageToPrint.htm") || print "ERROR: Could
not open HTLMLPAGE $FolderPath/$HtmlPageToPrint.htm to print the data: $!";
foreach (@HtmlTemplate) {
my $xdata = $_;
$xdata =~ s/(\$\w+)/$1/eeg; # Process the variables
print HTLMLPAGE "$xdata";
}
close(HTLMLPAGE);
}# End of foreach
} # end of sub
1;
############# This also works fully but doesn't use template.
#
# #foreach (@HtmlTemplate) {
# #my $xdata = $_;
# #$xdata =~ s/(\$\w+)/$1/eeg; # Process the
variables
# #print HTLMLPAGE "$xdata";
# print HTLMLPAGE "$HTMLPageData";
# #}
# close(HTLMLPAGE);