furenberger has asked for the wisdom of the Perl Monks concerning the following question:

We have a phone directory lookup script where a user searches for whetever letters they want and the script returns matches found in a flat file. When a user searches for the letters "pl" the script returns all results (it should only filter those results where the searchArg string matches the searchThisLine string.

Here is the HTML output that I have added for debug:
Searching pl in AARON SCOTT E 664 8169 E07L 25/12 EMPLOYEE AARON AAR1069
true
Here is the code snippet that is causing the problem.
my $searchThisLine = $lastname . " " . $firstname . " " . $alias . " " + . $phPrefix . " " . $phSuffix . " " . $location . " " . $deptdivcode +slash . " " . $line[16] . " " . $contractorfirm . " " . $nospacelastn +ame . " " . $lanID; foreach my $searchArg(@argument) { print "<br> Searching $searchArg in $searchThisLine<br>"; #search for searchArg in searchThisLine #true means the searchArg was found - so continue processing line #false means the searchArg was not found - so break loop if ($searchThisLine =~ m/$searchArg/i) { print "<br>true<br>"; #this shouldn’t be happening when the user searches pl } else { print "<br>false<br>"; #set the search match flag to false # and call last so this iteration will stop $bSearchMatch = "false"; last; } ...
What am I missing here?

Replies are listed 'Best First'.
Re: Perl string matching pl
by keszler (Priest) on Oct 04, 2011 at 13:12 UTC

    emPLoyee?

      OH DUH. much appreciated.
Re: Perl string matching pl
by toolic (Bishop) on Oct 04, 2011 at 13:14 UTC
    if ($searchThisLine =~ m/$searchArg/i)
    The /i flag enables case-insensitive matching. So, the PL in EMPLOYEE matches m/pl/i. See perlre

    If you only want to match lower-case pl, use: m/$searchArg/