http://www.perlmonks.org?node_id=1101152


in reply to Improving if statements

Multiple if statements are really redundant, that is true, but not necessarily a bad thing unless readability of the code becomes difficult. I find the solutions by Your Mother and choroba to be very educational, succinct and efficient. It may be also relevant to include the utility of the Switch module for tasks like testing different cases and responsing to each case.

use strict; use warnings; use Switch; my $item = $ARGV[0]; switch($item){ case "moo" {print "cow"} case "test" {print "blue"} case "dark" {print "black"} case "white" {print "light"} case "house" {print "home"} case "all things" {print "multi"} case "money" {print "value"} case "country" {print "Well, not Scotland apparently"} else {print "NAOAOAOANOOOO!!!" } }
UPDATE: The use of switch statements in the way I recommended may not be a favorable option judging by the amount of downvotes my reply received. Thanks Tobylink for elaborating on problems with Switch statements, I definitely learned something new about them.

David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...