I have successfully been able to assign separate filehandles to scalers, search and return results, however, both file search results return in both placeholders. I need to assign a $line3 to $main_template =~ s/%%searcresults%%/$pitem/g; and $line2 to $main_template =~ s/%%premiumresults%%/$premiumitem/g;
$pitem and $premiumitem only represent the HTML file insertion names and are not relevant here. I am thinking I need an if, elsif and else statement somewhere so that $main_template =~ s/%%searcresults%%/$pitem/g; is printed as $line2 if the results are found in SIDX, that $main_template =~ s/%%premiumresults%%/$premiumitem/g; is printed as $line2 if the results are found in SIDX2, and that both are printed if the results were found in both SIDX and SIDX2.
Code:
$main_template =~ s/%%keywords%%/$fields{'keywords'}/g;
$main_template =~ s/%%searcresults%%/$pitem/g;
$main_template =~ s/%%premiumresults%%/$premiumitem/g;
$pitem and $premiumitem only represent the HTML file insertion names and are not relevant here. I am thinking I need an if, elsif and else statement somewhere so that $main_template =~ s/%%searcresults%%/$pitem/g; is printed as $line2 if the results are found in SIDX, that $main_template =~ s/%%premiumresults%%/$premiumitem/g; is printed as $line2 if the results are found in SIDX2, and that both are printed if the results were found in both SIDX and SIDX2.
Code:
foreach $item (@skeyw){$nrkeywords++;}
open (SIDX, "$data_dir/search.idx");
open (SIDX2, "$data_dir/search2.idx");
if ($file_locking ne "No"){flock (SIDX, LOCK_SH) or die "Can't set lock for file: $data_dir/search.idx, $data_dir/search2.idx $!\n";}
while($line3 = <SIDX>)
{
$line2 = <SIDX2>;
$sline = "${line1}${line2}${line3}";
foreach $kwr (@skeyw)
{
if (($sline =~ /$kwr/i) and ($kwr ne ""))
##### here is where I believe I need to assign $main_template =~ s/%%searcresults%%/$pitem/g;
{
##### here is where I believe I need to assign elsif $main_template =~ s/%%premiumresults%%/$premiumitem/g;
##### here is where I believe I need to assign else $main_template =~ s/%%premiumresults%%/$premiumitem/g;
$toadk = "true";
}
}
if ($toadk eq "true")
{
#### substituting $premium_resultline[$icnt] = "${line2}"; with $main_template =~ s/%%premiumresults%%/$premiumitem/${line2}; does not work below
#### substituting $resultline[$icnt] = "${line2}"; with $main_template =~ s/%%searcresults%%/$premiumitem/${line2}; does not work below
$premium_resultline[$icnt] = "${line2}";
$resultline[$icnt] = "${line3}";
$toadk = false;
$icnt++;
}
}
#if ($file_locking ne "No"){flock (CIT, LOCK_UN);}
close (SIDX);
close (SIDX2);
}
$main_template = html::insert_tmpl_includes($main_template);
print "$main_template";
exit;