Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Ensuring Each If Statement Is Evaluated

by ignatz (Vicar)
on Oct 17, 2002 at 08:31 UTC ( #205955=note: print w/replies, xml ) Need Help??

in reply to Ensuring Each If Statement Is Evaluated

else and elsifs only get checked if every if and elsif before it was false:
#!/usr/bin/perl -w use strict; my $bool = 1; if ($bool) { print "/\$bool: I'm true, so this get's printed.\n"; } elsif ($bool) { print "/\$bool: You'll never see me if I'm true.\n"; } else { print "/\$bool: Nobody loves me, everybody hates me.\n"; }
If you want to check every condition, use a serious of ifs:
if ($bool) { print "/\$bool I'm true, so this get's printed.\n"; } if ($bool == 1) { print "/\$bool You love me! You really love me!\n"; } if ($bool != 2) { print "/\$bool First, I want to think my manager...\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://205955]
[erix]: Harakiri with a nuke on the white house, that'd clean up the staff there a bit too ;)
[erix]: (sorry, I'm always a bit violent on fridays)
LanX predicts problems for Erix next time he lines up at an US immigration counter
[erix]: but tuesdays just as bad
[erix]: thanks for the heads-up but that's a line-up studiiously avoided :P
[LanX]: yeah too far for someone who can't even make it to Amsterdam

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-08-18 13:16 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (302 votes). Check out past polls.