I have been stuck 2 days on this code. I am using Perl to create directories with HTML files. The directories are being created but the HTML files are not. Can anyone see what is the problem with my code here? Any suggestions or information would be appreciated. Thank you in advance.
#!/C/Perl/bin/perl
use MSSQL:Blib;
use MSSQL:Blib::Const::General;
$dbh = MSSQL:Blib->dblogin('123', 'password123', 'COMP_NAME', 'DB_NAME');
print "1\n";
$query = "SELECT a.businessTypeId as MYBTID, a.*, businessIndustryDescription, businessTypeDescription FROM db1.dbo.Business a, db1.dbo.BusinessIndustry b, db1.dbo.BusinessType c WHERE a.BusinessIndustryId = b.BusinessIndustryId AND a.BusinessTypeId = c.BusinessTypeId AND a.BusinessStatusId = 1 ORDER BY MYBTID";
$dbh->dbcmd($query);
$dbh->dbsqlexec;
$dbh->dbresults;
$curr = 0;
while($dbh->dbnextrow2($dataref, 1) != NO_MORE_ROWS) {
### $businessIndustryId = $$dataref{"businessIndustryId"};
$businessTypeId = $$dataref{"businessTypeId"};
######$businessTypeId = $$dataref{"MYBTID"};
# new category??
### if ($curr != $businessIndustryId) {
if ($curr != $businessTypeId) {
# close category file
if ($curr != 0) {
open (FOOTERTEMPLATE, "litefooter.html");
@footer = <FOOTERTEMPLATE>;
close (FOOTERTEMPLATE);
foreach $line (@footer) {
print CATFILE $line;
}
close (CATFILE);
}
# create new directory
### $curr = $businessIndustryId;
### $dir = $$dataref{"businessIndustryDescription"};
### $dir =~ s/ /_/g;
### mkdir ($dir);
$curr = $businessTypeId;
###### can't comment out dir or directories don't get created, why?
$dir = $$dataref{"businessIndustryDescription"};
$dir2 = $$dataref{"businessTypeDescription"};
$dir2 =~ s/ /_/g;
mkdir ($dir2);
# create header of category file
### open (CATFILE, "> $dir/litecatlistings.html");
open (CATFILE, "> $dir2/litecatlistings.html");
$bizti = "TEST";
$metabizti = "TEST";
open (HEADERTEMPLATE, "litecatheader.html");
@header = <HEADERTEMPLATE>;
close (HEADERTEMPLATE);
foreach $line (@header) {
###### $line =~ s/--TITLE--/$$dataref{"businessTypeDescription"}/;
$line =~ s/--TITLE--/$$dataref{"businessIndustryDescription"}/;
$line =~ s/--BIZTYPEINFO--/$bizti/;
$line =~ s/--METABIZTYPEINFO--/$metabizti/;
print CATFILE $line;
}
}
# append body part category file
open (BODYTEMPLATE, "litecatbody.html");
@body = <BODYTEMPLATE>;
close (BODYTEMPLATE);
foreach $line (@body) {
$line =~ s/--BUSINESSTITLE--/$$dataref{"businessTitle"}/;
$state = $$dataref{"businessState"};
$country = $$dataref{"businessCountry"};
if ($state !~ m/^\s*$/ && $country !~ m/^\s*$/) {
$location = $state.",".$country;
}
elsif ($state !~ m/^\s*$/) {
$location = $state;
}
elsif ($country !~ m/^\s*$/) {
$location = $country;
}
else {
$location = "N/A";
}
$line =~ s/--LOCATION--/$location/;
$description = $$dataref{"businessDescription"};
if (length ($description) > 100) {
$description = substr ($description, 0, 97)."...";
}
$line =~ s/--DESCRIPTION--/$description/;
$url = "listing".($$dataref{"businessId"}*9).".html";
##$mydir = $$dataref{"businessIndustryDescription"};
$myurl = "
####$line =~ s/--URL--/$url/;
$line =~ s/--URL--/$myurl/;
print CATFILE $line;
}
# create listing file
### open (LISTINGFILE, "> $dir/$url");
open (LISTINGFILE, "> $dir2/$url");
open (HEADERTEMPLATE, "litecatheaderForListing.html");
@header = <HEADERTEMPLATE>;
close (HEADERTEMPLATE);
foreach $line (@header) {
### $line =~ s/--TITLE--/$$dataref{"businessIndustryDescription"}/;
$line =~ s/--TITLE--/$$dataref{"businessTypeDescription"}/;
#for metatags
$line =~ s/--BUSINESSTITLE--/$$dataref{"businessTitle"}/;
$line =~ s/--LOCATION--/$location/;
$line =~ s/--BIZCATSEOINFO--/$bizti/;
print LISTINGFILE $line;
}
open (BODYTEMPLATE, "litelistingbody.html");
@body = <BODYTEMPLATE>;
close (BODYTEMPLATE);
foreach $line (@body) {
$line =~ s/--BUSINESSTITLE--/$$dataref{"businessTitle"}/;
$state = $$dataref{"businessState"};
$country = $$dataref{"businessCountry"};
if ($state !~ m/^\s*$/ && $country !~ m/^\s*$/) {
$location = $state.",".$country;
}
elsif ($state !~ m/^\s*$/) {
$location = $state;
}
elsif ($country !~ m/^\s*$/) {
$location = $country;
}
else {
$location = "N/A";
}
$line =~ s/--LOCATION--/$location/;
####$line =~ s/--LOCATION--/$location." ".$bizti/;
$line =~ s/--DESCRIPTION--/$$dataref{"businessDescription"}/;
$line =~ s/--USERID--/$$dataref{"businessId"}/;
if ($line =~ m/--ASKINGPRICE--/) {
if ($$dataref{"businessAskingPrice"} !~ m/^\s*$/) {
$line =~ s/--ASKINGPRICE--/$$dataref{"businessAskingPrice"}/;
}
else { $line = ""; }
}
if ($line =~ m/--REVENUE--/) {
if ($$dataref{"businessSalesRevenue"} !~ m/^\s*$/) {
$line =~ s/--REVENUE--/$$dataref{"businessSalesRevenue"}/;
}
else { $line = ""; }
}
if ($line =~ m/--INVENTORY--/) {
if ($$dataref{"businessInventory"} !~ m/^\s*$/) {
$line =~ s/--INVENTORY--/$$dataref{"businessInventory"}/;
}
else { $line = ""; }
}
print LISTINGFILE $line;
}
open (FOOTERTEMPLATE, "litefooter.html");
@footer = <FOOTERTEMPLATE>;
close (FOOTERTEMPLATE);
foreach $line (@footer) {
print LISTINGFILE $line;
}
close (LISTINGFILE);
}
open (FOOTERTEMPLATE, "litefooter.html");
@footer = <FOOTERTEMPLATE>;
close (FOOTERTEMPLATE);
foreach $line (@footer) {
print CATFILE $line;
}
close (CATFILE);
print "script Finished!\n";
$dbh->dbcancel;
$dbh->dbclose;
#!/C/Perl/bin/perl
use MSSQL:Blib;
use MSSQL:Blib::Const::General;
$dbh = MSSQL:Blib->dblogin('123', 'password123', 'COMP_NAME', 'DB_NAME');
print "1\n";
$query = "SELECT a.businessTypeId as MYBTID, a.*, businessIndustryDescription, businessTypeDescription FROM db1.dbo.Business a, db1.dbo.BusinessIndustry b, db1.dbo.BusinessType c WHERE a.BusinessIndustryId = b.BusinessIndustryId AND a.BusinessTypeId = c.BusinessTypeId AND a.BusinessStatusId = 1 ORDER BY MYBTID";
$dbh->dbcmd($query);
$dbh->dbsqlexec;
$dbh->dbresults;
$curr = 0;
while($dbh->dbnextrow2($dataref, 1) != NO_MORE_ROWS) {
### $businessIndustryId = $$dataref{"businessIndustryId"};
$businessTypeId = $$dataref{"businessTypeId"};
######$businessTypeId = $$dataref{"MYBTID"};
# new category??
### if ($curr != $businessIndustryId) {
if ($curr != $businessTypeId) {
# close category file
if ($curr != 0) {
open (FOOTERTEMPLATE, "litefooter.html");
@footer = <FOOTERTEMPLATE>;
close (FOOTERTEMPLATE);
foreach $line (@footer) {
print CATFILE $line;
}
close (CATFILE);
}
# create new directory
### $curr = $businessIndustryId;
### $dir = $$dataref{"businessIndustryDescription"};
### $dir =~ s/ /_/g;
### mkdir ($dir);
$curr = $businessTypeId;
###### can't comment out dir or directories don't get created, why?
$dir = $$dataref{"businessIndustryDescription"};
$dir2 = $$dataref{"businessTypeDescription"};
$dir2 =~ s/ /_/g;
mkdir ($dir2);
# create header of category file
### open (CATFILE, "> $dir/litecatlistings.html");
open (CATFILE, "> $dir2/litecatlistings.html");
$bizti = "TEST";
$metabizti = "TEST";
open (HEADERTEMPLATE, "litecatheader.html");
@header = <HEADERTEMPLATE>;
close (HEADERTEMPLATE);
foreach $line (@header) {
###### $line =~ s/--TITLE--/$$dataref{"businessTypeDescription"}/;
$line =~ s/--TITLE--/$$dataref{"businessIndustryDescription"}/;
$line =~ s/--BIZTYPEINFO--/$bizti/;
$line =~ s/--METABIZTYPEINFO--/$metabizti/;
print CATFILE $line;
}
}
# append body part category file
open (BODYTEMPLATE, "litecatbody.html");
@body = <BODYTEMPLATE>;
close (BODYTEMPLATE);
foreach $line (@body) {
$line =~ s/--BUSINESSTITLE--/$$dataref{"businessTitle"}/;
$state = $$dataref{"businessState"};
$country = $$dataref{"businessCountry"};
if ($state !~ m/^\s*$/ && $country !~ m/^\s*$/) {
$location = $state.",".$country;
}
elsif ($state !~ m/^\s*$/) {
$location = $state;
}
elsif ($country !~ m/^\s*$/) {
$location = $country;
}
else {
$location = "N/A";
}
$line =~ s/--LOCATION--/$location/;
$description = $$dataref{"businessDescription"};
if (length ($description) > 100) {
$description = substr ($description, 0, 97)."...";
}
$line =~ s/--DESCRIPTION--/$description/;
$url = "listing".($$dataref{"businessId"}*9).".html";
##$mydir = $$dataref{"businessIndustryDescription"};
$myurl = "
####$line =~ s/--URL--/$url/;
$line =~ s/--URL--/$myurl/;
print CATFILE $line;
}
# create listing file
### open (LISTINGFILE, "> $dir/$url");
open (LISTINGFILE, "> $dir2/$url");
open (HEADERTEMPLATE, "litecatheaderForListing.html");
@header = <HEADERTEMPLATE>;
close (HEADERTEMPLATE);
foreach $line (@header) {
### $line =~ s/--TITLE--/$$dataref{"businessIndustryDescription"}/;
$line =~ s/--TITLE--/$$dataref{"businessTypeDescription"}/;
#for metatags
$line =~ s/--BUSINESSTITLE--/$$dataref{"businessTitle"}/;
$line =~ s/--LOCATION--/$location/;
$line =~ s/--BIZCATSEOINFO--/$bizti/;
print LISTINGFILE $line;
}
open (BODYTEMPLATE, "litelistingbody.html");
@body = <BODYTEMPLATE>;
close (BODYTEMPLATE);
foreach $line (@body) {
$line =~ s/--BUSINESSTITLE--/$$dataref{"businessTitle"}/;
$state = $$dataref{"businessState"};
$country = $$dataref{"businessCountry"};
if ($state !~ m/^\s*$/ && $country !~ m/^\s*$/) {
$location = $state.",".$country;
}
elsif ($state !~ m/^\s*$/) {
$location = $state;
}
elsif ($country !~ m/^\s*$/) {
$location = $country;
}
else {
$location = "N/A";
}
$line =~ s/--LOCATION--/$location/;
####$line =~ s/--LOCATION--/$location." ".$bizti/;
$line =~ s/--DESCRIPTION--/$$dataref{"businessDescription"}/;
$line =~ s/--USERID--/$$dataref{"businessId"}/;
if ($line =~ m/--ASKINGPRICE--/) {
if ($$dataref{"businessAskingPrice"} !~ m/^\s*$/) {
$line =~ s/--ASKINGPRICE--/$$dataref{"businessAskingPrice"}/;
}
else { $line = ""; }
}
if ($line =~ m/--REVENUE--/) {
if ($$dataref{"businessSalesRevenue"} !~ m/^\s*$/) {
$line =~ s/--REVENUE--/$$dataref{"businessSalesRevenue"}/;
}
else { $line = ""; }
}
if ($line =~ m/--INVENTORY--/) {
if ($$dataref{"businessInventory"} !~ m/^\s*$/) {
$line =~ s/--INVENTORY--/$$dataref{"businessInventory"}/;
}
else { $line = ""; }
}
print LISTINGFILE $line;
}
open (FOOTERTEMPLATE, "litefooter.html");
@footer = <FOOTERTEMPLATE>;
close (FOOTERTEMPLATE);
foreach $line (@footer) {
print LISTINGFILE $line;
}
close (LISTINGFILE);
}
open (FOOTERTEMPLATE, "litefooter.html");
@footer = <FOOTERTEMPLATE>;
close (FOOTERTEMPLATE);
foreach $line (@footer) {
print CATFILE $line;
}
close (CATFILE);
print "script Finished!\n";
$dbh->dbcancel;
$dbh->dbclose;