Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Re: Word Evaluation

by hotshot (Prior)
on Jan 29, 2003 at 16:48 UTC ( [id://231004]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Word Evaluation
in thread Word Evaluation

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://231004]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-16 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found