Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Separating multiple keyword search input

by Anonymous Monk
on Jun 29, 2004 at 02:14 UTC ( [id://370389]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I seek wisdom in regards to referencing an assigned scaler variable - $search_line = $fields{'keywords'}; and a 2nd scaler variable which performs the same funtion - $search_line2 = $fields{'keywords'};. The 2nd variable must not eliminate the value of the first, but include the same assignment from a different file. Initially, I need to separate the return results of search_line and search_line2. The initial assignment opens 2 files (by design) Assignment:
foreach $item (@resultline, @premium_resultline)
open (SIDX, "$data_dir/search.idx"); open (SIDX2, "$data_dir/search2.idx");
then pulls in 2/both files for reading/search simultaneously:
(@skeyw) = split(/ /,$search_line);
if ($file_locking ne "No"){flock (SIDX, LOCK_SH) or die "Can't set loc +k 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}"; # $resultline[$icnt] = "${line1}${line2}${line3}"; $toadk = false; $icnt++; } } #if ($file_locking ne "No"){flock (CIT, LOCK_UN);} close (SIDX); close (SIDX2); }
I am thinking this for logic reasons: $search_line = $fields{'keywords'}; $search_line2 = $fields{'keywords'};
(@skeyw) = split(/ /,$search_line); (@skeyw) = split(/ /,$search_line2);
However this does not allow for logic since I need the @skeyw to split itself once yet recognize that SIDX and SIDX2 are separate files. The search result return is:
sub get_search_ready { my ($search_line) = @_; my ($search_line2) = @premium_resultline; $reline = $search_line; $reline = $search_line2; $reline =~ s/[+\[\]()*^.\$?\\~<>;]//g; return ($reline); }

Replies are listed 'Best First'.
Re: Separating multiple keyword search input
by jarich (Curate) on Jun 29, 2004 at 05:54 UTC
    G'day Dente, nice to see you again.

    If I recall correctly you've already asked a very similar question a couple of times:

    I'm not quite sure what was wrong in my original answer: 350643.

    Perhaps now would be a good time to step away from the code and give us a broad description of what you're trying to achieve.

    It might go something like the following:

    I have two files with search indexes in them. My criteria for these search indexes are different for both files. I would like a suggestion on how I can ... and get back ...

    We can see the code, but it's not helping us understand the problem you're trying to solve.

    all the best,

    jarich

    Update:

    Just thought I'd point out that you've also had some very good answers at yet another attempt at this question over here: Separating multiple keyword search input.

Re: Separating multiple keyword search input
by NetWallah (Canon) on Jun 29, 2004 at 03:07 UTC
    It is not clear what you are asking.

    For information about perl hashes, please read the "perldata" documentation.
    It seems like you would like to construct a hash with keywords, so you can reference it like :

    my %kwhash = (word1=> undef, word2=>undef); # SPLIT your line of input, then match each word while (my $line = <SIDX2>){ for my $word (split / /, $line){ if (defined $kwhash{$word}){ # Process for FOUND keyword } }

        Earth first! (We'll rob the other planets later)

Re: Separating multiple keyword search input
by BrowserUk (Patriarch) on Jun 29, 2004 at 04:33 UTC

    Sorry, but your question is most unclear.

    In your code, you have two files and $line2 is read from one file and $line3 is read from the second file, but $sline = "${line1}${line2}${line3}";. Where does $line1 come from?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://370389]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-19 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found