CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Regex

 



stanley
Novice

Mar 27, 2001, 6:01 PM

Post #1 of 3 (350 views)
Regex Can't Post

Okay I have these:

$word[1]='island|beach';
$go[1]='http://www.go.com/island';
$word[2]='hawaii island|hawaii beach';
$go[2]='http://www.go.com/hawaiiisland';



for($i=0; $i<@word; $i++) {
if($query=~ m/\s*$word[$i]/i) {
$load=$go[$i];
}

I need to do an exact match, which means when user search using keyword "island", it will goto the $go[1] while using keyword "hawaii island" will goes to $go[2].

Curently, when I try to do a search word using "hawaii island", it goes to $go[1]......pls help...thanks



rGeoffrey
User / Moderator

Mar 27, 2001, 7:42 PM

Post #2 of 3 (347 views)
Re: Regex [In reply to] Can't Post

The reason you matched the longer version is because you were looking for white space followed by the $word and the second one is a match, so you replace the first answer to $load.

You could try something that looks like...


Code
my (%indexes, $ct); 

foreach my $line (@word) {
foreach (split ('|', $line) {
$indexes{lc ($_)} = $ct;
}
$ct++;
}

$load = $go[$indexes{lc ($word)}];

It builds a hash with all the valid exact matches as the keys and the values are indexes into @go. To deal with upper and lower case problems we lowercase the keys and the $word we look for.

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


stanley
Novice

Mar 29, 2001, 9:18 AM

Post #3 of 3 (333 views)
Re: Regex [In reply to] Can't Post

Oh, I still don't understand how to apply this to my code......


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives