in reply to Re: Using the 'if' statement...
in thread Using the 'if' statement...


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

Replies are listed 'Best First'.
Re^3: Using the 'if' statement...
by ikegami (Patriarch) on Jul 09, 2008 at 10:05 UTC

    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.

Re^3: Using the 'if' statement...
by DrHyde (Prior) on Jul 09, 2008 at 10:29 UTC
    You need to anchor your pattern match in grep, otherwise ...
    @countries = qw(India Germany); $country = 'd'; print "True","\n" if ( grep /$country/, @countries );