in reply to Word Evaluation

Let me see if I understand your problem: you have a list of strings, such as "bar", "bartender", and "foobar". You want to get rid of any duplicates, but you have to make sure that "bar" won't match against "bartender" or "foobar".

First solution that comes to mind is to ignore the regex and simply use string eq:

next if($word eq $w);

If you really need a regex for some reason, use \s to match whitespace around the word:

next if($word =~ /\s$w\s/);

Replies are listed 'Best First'.
Re: Re: Word Evaluation
by Gilimanjaro (Hermit) on Jan 29, 2003 at 17:21 UTC
    Probably better check for word boundaries around the word, as they will also match the beginning and end of string;

    next if $word=~/\b$w\b/;
      Or you can use the slightly more longwinded form using alternations that allows $w to start with non-work characters (\b looks at the change between \W to \w not \s and \S):
      next if $word =~ /(^|\s)$w(\s|$)/;

      --
      integral, resident of freenode's #perl