Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning scalars to template includes

Status
Not open for further replies.

artisst

Programmer
Apr 24, 2004
18
US
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;

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;
 
Could you please rephrase the question, I can't make any chocolat out of the description...
 
I need to assign <FILEHANDLE> search results to $main_template includes

If keywords are found in <SIDX> only then:

Code:
$main_template =~ s/%%searcresults%%/$pitem/g;

If keywords are found in <SIDX2> only then:
Code:
$main_template =~ s/%%premiumresults%%/$premiumitem/g;

If keywords are found in both <SIDX> and <SIDX2> then:
Code:
$main_template =~ s/%%searcresults%%/$pitem/g;
$main_template =~ s/%%premiumresults%%/$premiumitem/g;

$pitem and $premiumitem are not relevant here.

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 "")) 
		
			$toadk = "true";
			}
		}

		if ($toadk eq "true")
			{
	
			$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;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top