in reply to Confused by a Conditional
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.#!/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"; }
The other common options are:
or put the list in a hash and write the test as:if (grep {$key eq $_} qw(ID TITLE GENE CYTOBAND LOCUSLINK CHROMOSOME S +COUNT)) { print "This didn't print, did it?\n"; }
if (exists $is_valid{$key}) { print "Key '$key' is a valid key\n"; }
|
|---|