Gossamer Forum
Home : General : Perl Programming :

Case Insensitive Searching

Quote Reply
Case Insensitive Searching
I have a database of words in a glossary. If a member posts news containing one of those words, the first instance will be changed to a link and a little popup can be pulled up with a definition. The problem is that I add these from a different form on the site (for ease of adding.)

If I should add a word like 'Apple' then only Apple (not apple or APPLE, although God forbid anyone doing that) will be matched.

Here is the code I am using.
(By the way, $typist[3] is the news post itself. The script scans that post and looks for any words in it that match the glossary words.)
sub doglossary {
open (LOGT, "../gloss/glossary.txt") || &ErrorMessage;
$glossary = <LOGT>;
close (LOGT);

@glossary = split(/\|/, $glossary);
foreach $gloss (@glossary) {
$typist[3] =~ s/$gloss/<a href=\"javascript:openPopWin(\'cdb.cgi?action=glossaryread&word=$gloss\',350,200,\ \'scrollbars\')\"><span class=gloss>$gloss<\/a><\/span>/;
}

Quote Reply
Re: Case Insensitive Searching In reply to
wait a second.. do you want case insensitive or do you not want case insensitive searching?

the code looks like it doesn't have case insensitive searching, so i guess you want it..

this should work the way you want it..

$typist[3] =~ s#($gloss)#<a href="javascript:openPopWin('cdb.cgi?action=glossaryread&word=$gloss',350,200, 'scrollbars')"><span class=gloss>$1</a></span>#i;

so basically.. it puts whatever case it finds the word in into a buffer $1.. and then the URL points to the word in the case it is in in the database.. and the word is replaced with the linked word in the original case..

Jerry Su
widgetz sucks
Quote Reply
Re: Case Insensitive Searching In reply to
Well, the code you gave me worked perfectly. Thanks!(And yes, I DID want case-insensative searching.)