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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:



Mar 27, 2001, 6:01 PM

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

Okay I have these:

$word[2]='hawaii island|hawaii beach';

for($i=0; $i<@word; $i++) {
if($query=~ m/\s*$word[$i]/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

User / Moderator

Mar 27, 2001, 7:42 PM

Post #2 of 3 (483 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...

my (%indexes, $ct); 

foreach my $line (@word) {
foreach (split ('|', $line) {
$indexes{lc ($_)} = $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?


Mar 29, 2001, 9:18 AM

Post #3 of 3 (469 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