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

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.

Replies are listed 'Best First'.
Re^6: search for exact word only
by Anonymous Monk on Sep 28, 2004 at 11:17 UTC
    Yes, this works.

    thank you for help,
    tenerif
Re^6: search for exact word only
by Anonymous Monk on Sep 29, 2004 at 10:39 UTC
    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.
        Its works now, thank you.
        Alex