in reply to Re: Using a variable as pattern in substitution
in thread Using a variable as pattern in substitution

Thanks for that, one thing when I first tried it it didn't work. My stop words were in a text file, one per line I had to

 chop $stopwords

to get it to work.

One more thing what does the \b mean?

Stew

Replies are listed 'Best First'.
Re (3): Using a variable as pattern in substitution
by VSarkiss (Monsignor) on Jun 05, 2002 at 16:21 UTC

    You can chomp every element in the array when you slurp the file: chomp(@stopwords = <FILE>);(As a side note, in general, chomp is preferable to chop.)

    The \b says to look for a word boundary. In other words, if your target string is part of another word, the \b will keep it from matching.

    my $target = "another"; $target =~ /other/; # this matches $target =~ /\bother/; # this doesn't
    You can read more about it in the perlre document.

Re^3: Using a variable as pattern in substitution
by Aristotle (Chancellor) on Jun 05, 2002 at 17:12 UTC
    Avoid chop unless you want to remove the last character from every line of your file. Are you sure the last one ends with a newline? If not, oops.. there goes a character of data. chomp is not so indiscriminate.

    Makeshifts last the longest.