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

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 '!=';}

Replies are listed 'Best First'.
Re^7: search for exact word only
by Roy Johnson (Monsignor) on Sep 29, 2004 at 13:09 UTC
    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