I have been successful n reading from 2 files and storing contents in an array but now I need to be able to extract the keywords from the array - @skeyw - that has the combined contents of 2 files <SIDX> and <SIDX2>, and split them into 2 separate returns, one return from the keywords found in <SIDX> and the other keywords found in <SIDX2>. They will be inserted into the html placeholders %%searchresults%% and the other in %%premiumresults%%:
$main_template =~ s/%%keywords%%/$fields{'keywords'}/g; $main_template =~ s/%%searcresults%%/$pitem/g; $main_template =~ s/%%keywords%%/$fields{'keywords'}/g; $main_template =~ s/%%premiumresults%%/$pitem/g; print "Content-type: text/html\n\n"; $main_template = tseek::insert_tmpl_includes($main_template); print "$main_template"; exit;
Here is where I do the search:
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"); open (SIDX2, "$data_dir/search2.idx"); if ($file_locking ne "No"){flock (SIDX, LOCK_SH) or die "Can't set lo +ck for file: $data_dir/search.idx, $data_dir/search2.idx $!\n";} while($line3 = <SIDX>) { $line2 = <SIDX2>; $sline = "${line2}${line3}"; foreach $kwr (@skeyw) { if (($sline =~ /$kwr/i) and ($kwr ne "")) { $toadk = "true"; } } if ($toadk eq "true") { $resultline[$icnt] = "${line2}"; $premium_resultline[$icnt] = "${line3}"; $toadk = false; $icnt++; } } #if ($file_locking ne "No"){flock (CIT, LOCK_UN);} close (SIDX); close (SIDX2); }
and here is where I need to split the keyword search results from both files that are still contained in @skeyw. Search results from <SIDX> assigned to ($search_line) = @_; and the search results from <SIDX2> assigned to ($premium_search_line) = @_;
sub get_search_ready { my ($search_line) = @_; $reline = $search_line; $reline =~ s/[+\[\]()*^.\$?\\~<>;]//g; return ($reline); } sub get_search_ready2 { my ($premium_search_line) = ${line2}; $premium_reline = $premium_search_line; $premium_reline =~ s/[+\[\]()*^.\$?\\~<>;]//g; return ($premium_reline); }

In reply to Array extraction and separate returns 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.