in reply to Re: Word Evaluation
in thread Word Evaluation

Thank you for replying. I am very new to this, so sorry for the confusion. I am adding words to a line, but do not want to duplicate. The 2 strings are $words and $w. However, if advertise is one word, I don't want the word "ad" to be left out. My expression is only checking if the 2 words are equal to each other, I need to be checking past the first 2 characters.

Replies are listed 'Best First'.
Re: Re: Re: Word Evaluation
by hotshot (Prior) on Jan 29, 2003 at 16:48 UTC
    If I understood right, you have a list of words in a string and you want to add a word to that string, the new word should not exist already in the words string, am I right till here? If yes then you should do as follows:
    # suppose you have: $line = qw(advanture door tree); # and $word is: $word = 'ad'; ... if ($line =~ /\b$word\b/) { next; } else { # add $word to the list } # only if $word will be exactly 'adventure' or 'door' it will be skipe +d over
    '\b' is a word boundry like a space a comma (anything that is not a-z, A-Z, 0-9 or '_'), so the regexp in the 'if' statement is exactly what you need.

    Hotshot