I have read and fully understand the humerous yet concisive "Clean Your Room" scenario. I appreciate you candor relating to my post.

I need to search 2 flat text files and return the search results in 2 separate columns. 1 column for international, and the other local listings. This search needs to open both files, read them, and return results. The HTML template I am using pulls search_line into a single column via %%searchresults%% . I have added a second include %%premiumlistings%% column adjacent to it. I know I need to assign each file to an array and then use the split / / function, but I seem to run into a problem using the while statement. I am using HTML::Template and Perl DBD::DBI Modules from CPAN. Tseek is a perl module inlcuded in the package but contains none of the variables necessary for search results. The data is text file which is tab delimited and the script is written totally in perl. Data files are created and stored in search.idx. I already have a solution to store user input data into search2.idx.

HTML Template:

<html> <head> <meta http-equiv="content-type" content="text/html;charset=iso +-8859-1"> <meta name="generator" content="Adobe GoLive 4"> <title>Search</title> <!-- Hide %%metadescription%% // End Hide --> </head> <body bgcolor="white"> <div align="left"> %%incl_mallheader%% <table border="0" cellspacing="0" cellpadding="1" width="8 +05" height="174"> <tr align="left"> <td width="23" valign="top"></td> <td valign="top" width="778"> <div align="left"> <table border="0" cellpadding="5" cellspac +ing="1" width="795"> <tr> <td width="556" valign="top"><font + face="Verdana" size="2"><strong>Search Results</strong></font><font +face="Verdana" size="2" color="#990000"><strong> </strong></font><fon +t face="Verdana" size="2">found </font><font face="Verdana" size="2" +color="#990000"><strong>%%link_matches%%</strong></font><font face="V +erdana" size="2"> matches searching for <strong>'</strong></font><fon +t face="Verdana" size="2" color="#990000"><strong>%%keywords%%</stron +g></font><font face="Verdana" size="2"><strong>'</strong></font><font + face="Verdana" size="2"><br> </font></td> <td valign="top" width="216" rowsp +an="4"><font face="Verdana" size="2">%%premiumlistings%%<br> </font> <p><font face="Verdana" size=" +2"><br> </font></td> </tr> <tr height="34"> <td width="556" height="34" valign +="top"><font face="Verdana" size="2"><br> %%searchresults%%<br> &nbsp;&nbsp;&nbsp;&nbsp; </fon +t></td> </tr> <tr> <td width="556" valign="top"> <center> <font face="Verdana" size= +"1">%%pages%%</font></center> </td> </tr> <tr> <td width="556" valign="top"></td> </tr> </table> </div> </td> </tr> </table> <table border="0" cellpadding="0" cellspacing="0" backgrou +nd="http://www.mdosn.com/mall/images/bar-bk.gif" width="741"> <tr height="29" bgcolor="#e5ecf9"> <td height="29" width="177"></td> <td height="29"> <form method="POST" action="http://www.mdosn.c +om/cgi-bin/directory/tsearch.cgi" enctype="x-www-form-urlencoded"> </td> <td height="29"></td> <td height="29"><input type="hidden" name="livebui +lt" value="live"></td> <td height="29" width="138"><input type="text" nam +e="keywords" size="21"></td> <td height="29" width="52"><font color="#003366" s +ize="1"><span class="lefttext"><input type="submit" value=" Search " +name="sbutton"></span></font></td> <td height="29"> </form> </td> <td height="29"><font color="#ff9900"> <form method="get" action="http://www.mdosn.co +m/cgi-bin/directory/malljump.cgi" onsubmit="location.href=jb.options[ +jb.selectedIndex].value; return false;"> </font></td> <td height="29"></td> cellspacing="0"> <tr> <td bgcolor="#3366cc" width="743"><img width="1" h +eight="1" src="(Empty Reference!)"></td> </tr> </table> <br> <table border="0" cellspacing="0" width="804" cellpadding= +"0"> <tr height="16"> <td width="804" valign="top" bgcolor="white" heigh +t="16"> <center> <font face="Verdana" size="1">%%incl_mallf +ooter%%</font></center> </td> </tr> </table> <p>&nbsp;</div> </body> </html>
Required is as follows
use Fcntl qw(:DEFAULT :flock); use CGI; use CGI::Carp qw(fatalsToBrowser); use tseek;
The script is as follow:
$main_template =~ s/%%keywords%%/$fields{'keywords'}/g; $main_template =~ s/%%searcresults%%/$pitem/g;
returns results in left column via %%searchresults%%
$main_template =~ s/%%keywords%%/$fields{'keywords'}/g; $main_template =~ s/%%premiumlistings%%/$premiumitem/g;
unfortunatly returns same results in right column via %%premiumresults%%. This is where the problem starts:
sub normal_search { ### PERFORM SEARCH $search_line = $fields{'keywords'}; $icnt = 0; $toadk = ""; (@skeyw) = split(/ /,$search_line); $nrkeywords = 0; foreach $item (@skeyw){$nrkeywords++;} open (SIDX, "$data_dir/search.idx"); added code below to open 2nd file 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";}
here's 1st problem (only opening and reading 1st file
while (defined($line=<SIDX>)) { $sline = $line; foreach $kwr (@skeyw) { if (($sline =~ /$kwr/i) and ($kwr ne "")) { $toadk = "true"; } } if ($toadk eq "true") { $resultline[$icnt] = $line; $toadk = false; $icnt++; } } #if ($file_locking ne "No"){flock (CIT, LOCK_UN);} close (SIDX); }
I need this to open both files and return the results of search.idx in the right column and search2.idx in the right. This is the latter area of importance:
$resultline[$rcc] = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\t" . $row[3] . "\t" . $row[4] . "\t" . $row[5] . "\t" . $row[6] . "\t" . $row[7] . "\t" . $row[8] . "\t" . $kinclude . "\n"; $rcc++; } $sth->finish; $dbh->disconnect; }
and finally:
sub get_search_ready { my ($search_line) = @_; $reline = $search_line; $reline =~ s/\+//g; $reline =~ s/\[//g; $reline =~ s/\]//g; $reline =~ s/\)//g; $reline =~ s/\(//g; $reline =~ s/\*//g; $reline =~ s/\^//g; #$reline =~ s/\.//g; $reline =~ s/\$//g; $reline =~ s/\?//g; $reline =~ s/\\//g; $reline =~ s/\~//g; $reline =~ s/<//g; $reline =~ s/>//g; $reline =~ s/;//g; return ($reline); }

janitored by ybiC: Balanced <readmore> tags around longish codeblock


In reply to Separating arrays for column search results by artisst

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.