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

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
  • Comment on Re: Re: Re: Re: Re: assigning flat file dbs to arrays

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: assigning flat file dbs to arrays
by jarich (Curate) on May 05, 2004 at 00:41 UTC
    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