On 6/14/11 Tue  Jun 14, 2011  7:47 AM, "Beware" <mathieu.hed...@gmail.com>
scribbled:

> Hi and thank you for your answer.
> 
> But how can i use it with a list of word.
> 

Use what? You need to put a little context in your messages so people can
help you without seeing previous messages.


If you have a list of words in an array (@words) and you want to see if some
string ($string) matches those words except for case and is not all
upper-case, there are several possibilities.

1. You can test if a string consists of only upper-case letters:

  if( $string =~ /^[A-Z]+$/ )

2. You can test if $string matches any of the words in @words in
case-insensitive fashion:

 
  for my $word ( @words ) {
    if( $string =~ /^$word$/i ) {
      # string matches
      last;  # no need for further tests
    }
  }

3. You can do both:

  for my $word ( @words ) {
    if( $string =~ /^$word$/i && $string ne uc $word ) {
      # string matches
      last;  # no need for further tests
    }
  }

(You can also set all members of @word to upper-case to begin with.)

What exactly are you trying to do? Can you provide a Perl program that
illustrates this?



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to