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...

In reply to Re: Improving if statements by biohisham
in thread Improving if statements by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.