Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Confused by a Conditional

by damian1301 (Curate)
on Jun 10, 2001 at 10:27 UTC ( [id://87277]=note: print w/replies, xml ) Need Help??


in reply to Confused by a Conditional

delete

Tiptoeing up to a Perl hacker.
Dave AKA damian

Replies are listed 'Best First'.
Re: Confused by a Conditional
by Abigail (Deacon) on Jun 10, 2001 at 18:09 UTC
    You are very, very wrong.
    'ID' or 'TITLE' or 'GENE' or 'CYTOBAND' or 'LOCUSLINK' or 'CHROMOSOME' or 'SCOUNT'
    evaluates to 'ID'.
    use strict; my $key = 'TITLE'; unless (($key) eq ('ID' or 'TITLE' or 'GENE' or 'CYTOBAND' or 'LOCUSLINK' or 'CHROMOSOME' or 'SCOUNT')) { print "Damian is wrong\n"; }
    This prints "Damian is wrong".

    -- Abigail

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: Confused by a Conditional
by ZZamboni (Curate) on Jun 10, 2001 at 20:12 UTC
    The only way the conditional in your snippet evaluates to true is if $key=='ID'. Try setting $key to 'GENE', for example (which is one of the valid values), and you'll see.

    --ZZamboni

      delete

      Tiptoeing up to a Perl hacker.
      Dave AKA damian

        This prints oh for me, just as I would expect. ActivePerl 5.005_03 on Win2K.

Re: Re: Confused by a Conditional
by CheeseLord (Deacon) on Jun 10, 2001 at 12:23 UTC

    I admit, that's pretty cool. But I personally like this just a bit better (only because it takes up less space on the line):

    #!/usr/bin/perl -w use strict; my $key = 'JUMP'; if ($key =~ /^(ID|TITLE|GENE|CYTOBAND|LOCUSLINK|CHROMOSOME|SCOUNT)$/) +{ print "I don't know why this is printing.\n"; }

    I think there's someway that might be broken, though, if I remember my reading on regexes... but if you chomp everything right, I think it will accomplish the same thing (with the added benefit(?) of placing exactly what it matched in $1).

    CheeseLord

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found