in reply to Using the 'if' statement...

The eq operator does not work like that, but you can use a regular expression:
my $pattern = join ('|', @countries); if ($country =~ /^($pattern)$/) { print "True\n" }
Or you could use a for loop, or map
update: inserted parens

Replies are listed 'Best First'.
Re^2: Using the 'if' statement...
by ikegami (Patriarch) on Jul 09, 2008 at 10:02 UTC
    Needlessly uses captures, and incorrectly assumes @countries contains regexps. Fix:
    my $pattern = join '|', map quotemeta, @countries; if ($country =~ /^(?:$pattern)$/) { print "True\n" }

    Or even

    my ($pattern) = map qr/^(?:$_)$/, join '|', map quotemeta, @countries; if ($country =~ $pattern) { print "True\n" }
Re^2: Using the 'if' statement...
by harishnuti (Beadle) on Jul 09, 2008 at 09:44 UTC

    Alternatively ,below online applies
    print "True","\n" if ( grep /$country/, @countries ); # if present print "False","\n" if (! grep /$country/, @countries ); # if not prese +nt

      Needlessly uses a regexp, the regexp isn't anchored, and incorrectly assumes $country contains a regexps. Fix:

      print "True","\n" if ( grep $_ eq $country, @countries );

      I essentially posted that already.

      You need to anchor your pattern match in grep, otherwise ...
      @countries = qw(India Germany); $country = 'd'; print "True","\n" if ( grep /$country/, @countries );