in reply to Re^3: search for exact word only
in thread search for exact word only

Could you put the lines you provided inside my code? I got '500 Internal Server Error'. I suspect, that probably I have incorrectly closed braces or not in the right place.

Thanks
tenerif

Replies are listed 'Best First'.
Re^5: search for exact word only
by Roy Johnson (Monsignor) on Sep 27, 2004 at 21:25 UTC
    You can just use your original code, and where you did have the pattern
    /\Q$key/
    replace it with
    /\b\Q$key\E\b/

    Caution: Contents may have been coded under pressure.
      Yes, this works.

      thank you for help,
      tenerif
      I would like determine why this code not worked, its possible,I has incorrectly inserted brace.
      if($action eq '!='){ $match{$a} = 0 if $line[$position]=~m/\Q$key/i; } else{$match{$a} = 1 if $line[$position]=~m/\Q$key/i;}

      Can be rewritten like so: $match{$a} = ($line[$position] =~ m/\b\Q$key\E\b/i) ? 1 : 0; $match{$a} = !$match{$a} if $action eq '!=';
      Is this correct? Please correct me if something wrong:
      if($action eq '!='){ $match{$a} = ($line[$position] =~ m/\b\Q$key\E\b/i +) ? 1 : 0; } else{$match{$a} = !$match{$a} if $action eq '!=';}
        You should not have the if and else. You should only have the two lines. The condition for your if is in the second line. The first line does the match and sets the truth value; the second line reverses the truth value if the action is not-equals.

        Caution: Contents may have been coded under pressure.