P is for Practical | |
PerlMonks |
Re: in search of a more elegant if then elseby FunkyMonk (Chancellor) |
on Feb 19, 2010 at 11:10 UTC ( [id://824135]=note: print w/replies, xml ) | Need Help?? |
As other Monks have suggested, the conditional operator does what you want. They have also pointed out that it can become difficult to read. However, if you set your code out carefully, the conditional operator can produce elegant and easy to read code. Consider:
But, in some circumstances, you may be able to use a hash table:
See perlop for the difference between the or (||) and defined or (//) operators
In Section
Seekers of Perl Wisdom
|
|