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

Re (tilly) 1: Confused by a Conditional

by tilly (Archbishop)
on Jun 09, 2001 at 21:17 UTC ( [id://87205]=note: print w/replies, xml ) Need Help??


in reply to Confused by a Conditional

It is parsed like this:
#!/usr/bin/perl -w use strict; my $key = 'JUMP'; if ( ($key eq 'ID') or ('TITLE') or ('GENE') or ('CYTOBAND') or ('LOCUSLINK') or ('CHROMOSOME') or ('SCOUNT') ) { print "I don't know why this is printing.\n"; }
and the chain of or's is broken at the first true statement. Namely 'TITLE'. You need to put a lot more "$key eq" statements in there.

The other common options are:

if (grep {$key eq $_} qw(ID TITLE GENE CYTOBAND LOCUSLINK CHROMOSOME S +COUNT)) { print "This didn't print, did it?\n"; }
or put the list in a hash and write the test as:
if (exists $is_valid{$key}) { print "Key '$key' is a valid key\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2025-06-23 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.