I need to search 2 flat text files and return the search results from each file individually in 2 separate columns. The HTML template I am using pulls search_line into a column via %%searchresults%%. I know I need to split the array nd assign the 2nd file a handle. Beyond this I am lost. I have added a second include %%premiumlistings%% column adjacent to it. Sample search.idx Source (search2.idx is also tab delimited:
20660 Gekko Gear Selection of winter sports apparel Apparel_a +nd_Accessories-Athletic_Clothing www.gekkogear.com/
HTML Template Includes: Simple HTML doc created in GoLive %%searchresults%% %%premiumlistings%% Required is as follows
use Fcntl qw(:DEFAULT :flock); use CGI; use CGI::Carp qw(fatalsToBrowser);
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;

janitored by ybiC: Closed final <code> tag, replaced (excessive for viewing) tabs with spaces, balanced <readmore> tags around longish codeblock


In reply to assigning flat file dbs to arrays by Dente

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.