Re: string comparison



Babacio wrote:
Shashank Khanvilkar <shashank@xxxxxxxxxxxxxxx> writes:
How can i make the below program print "right choice".

$a = "apple";

if ($a eq ('apple'|'banana')){
    print "right choice\n";
}else{
    print "wrong choice\n";
}

But if I guess what you really want to do, try that :


if ($a eq 'apple' || $a eq 'banana') { etc }

or this:

    if ( grep $a eq $_, ('apple', 'banana') ) {

(perldoc -f grep)

And read some documentation,

Indeed.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.