in reply to Split question...

What is the best way to split each keyword?

The docs on split (in perlfunc) mention a special-case for dealing with multiple spaces.

When you do

($key1,$search_keys) = split / /, $search_keys, 2;
is it your plan to do this in a loop, pulling of next search term each time through? I would think it would be easier to just do
@keys = split / /, $search_keys;
Or is there something about item numbers that makes it easier to do it your way?

Replies are listed 'Best First'.
Re: Re: Split question...
by powerhouse (Friar) on Apr 21, 2003 at 17:46 UTC
    Well, here is how I'm doing it....
    $search_keys = $in{keywords}; while ($search_keys) { ($key1,$search_keys) = split /\s/, $search_keys, 2; if (Check_Database($key1)) { # checks if item num $page_content .= Get_Search_Results($key1,"item_num"); } else { $search_engine .= Get_Search_Results($key1,"keyword"); } }

    That is not working though. I don't know why, I guess I'll just play with it, while taking Mad Hatters advice of /\s+/ in the split, just in case they put more spaces then 1.

    Thank you for your advice.

    thx,
    Richard
      Wouldn't it be easier to do something like
      @search_keys = split /\s+/, $in{keywords}; foreach $key (@search_keys) { if (Check_Database($key)) { # checks if item num $page_content .= Get_Search_Results($key,"item_num"); } else { $search_engine .= Get_Search_Results($key,"keyword"); } }