Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Re: Re: assigning flat file dbs to arrays

by jarich (Curate)
on Apr 29, 2004 at 03:22 UTC ( [id://349004]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: assigning flat file dbs to arrays
in thread assigning flat file dbs to arrays

To be honest, I'm not quite sure what you're asking here. So I'm going to take a wild stab in the dark. You say the 2 arrays populate both includes showing the same search results.. I'm not sure what you mean by both includes and I don't know if you've added any code to the section where I wrote do something with search results.

If you have, you should show me the relevant code.

What the code I've provided you with does is the following. For each element in @sidx, copy that element into $line and REMOVE an element from @sidx2 which is put into $premiumline. Note that this means that @sidx2 will be EMPTY at the end of the foreach loop. (To avoid this make a copy of @sidx2 before the foreach loop and unshift off that instead.)

Once we've got $line and $premiumline we join them together into $sline. We then test if $sline matches what we're looking for in either $line or $premiumline and if it does we SAVE (only) $line into $resultline ($premiumline then gets thrown away).

Maybe this isn't what you want to be doing. Maybe you want to be doing this:

  • Foreach element in @sidx, keep it (save it in @resultline) if it matches any test in @skeyw.
  • Foreach element in @sidx2, keep it (save it in @resultline2) if it matches any test in @premiumkeyw.

Maybe you're trying to do something else...

Since you haven't specified what you want to be doing I think it would be futile for me to guess. Think about what you want to do in a broader sense and I'll be able to help you better.

All the best,

jarich

  • Comment on Re: Re: Re: Re: assigning flat file dbs to arrays

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: assigning flat file dbs to arrays
by Dente (Acolyte) on May 03, 2004 at 23:32 UTC
    I am try to create a site similar to google. The main search results in one column and the other in another. Initially, I did not have this in mind at the onset on this project. Rather than do a complete rewrite, I was hoping the were alternative solutions to my dilemma. Foreach element in @sidx, keep it (save it in @resultline) if it matches any test in @skeyw. Foreach element in @sidx2, keep it (save it in @resultline2) if it matches any test in @premiumkeyw. Your code is the premise upon which I would like to build upon. Thank you for your time
      Foreach element in @sidx, keep it (save it in @resultline) if it matches any test in @skeyw. Foreach element in @sidx2, keep it (save it in @resultline2) if it matches any test in @premiumkeyw.
      Well that's pretty easy then.

      # Remove empty strings from @skeyw and @premiumkeyw @skeyw = grep {$_ ne ""} @skeyw; @premiumkeyw = grep {$_ ne ""} @premiumkeyw; # Build a big regular expression out of @skeyw # for faster matching. my $skeyw_regexp = join('|', @skeyw); $skeyw_regexp = qr/$skeyw_regexp/; # Repeat for @premiumkeyw my $premium_regexp = join('|', @premiumkeyw); $premium_regexp = qr/$premium_regexp/; # Foreach line in @sidx foreach my $line (@sidx) { # Keep it (save it in @resultline) if it matches # any test in @skeyw. if($line =~ /$skeyw_regexp/) { # do something with search results push @resultline, $line; $icnt++; # do you need this? } } # Foreach element in @sidx2 foreach my $line (@sidx2) { # Keep it (save it in @resultline2) if it matches # any test in @premiumkey. if($line =~ /$premium_regexp/) { # do something with search results push @resultline2, $line; $icnt++; # do you need this? } }
      Hope it helps

      jarich

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2024-04-23 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found