You mean "is if..elseif..else" efficient?

Yes it is!

You can sometimes reorder your conditions to ensure that the most common (or least expensive to evaluate) comes first, but apart from that there are no glaring efficeiency problems here.

You do have a syntax error though. The semicolons after the if-clause and the endif-clause are not only superfluous but downright wrong.
The entire 'if(..){...}elseif(..){..}else{..}' is one statement. Note the braces and parentheses. They are all required.

if (defined(foo_2)){ do bar; } elsif (defined(foo_1)){ do foo_2; } else { do foo_1; };
Would be more correct. But still not quite there. Variables have a '$' in front of them (mostly), and do is not the preferred way of calling subroutines.....


In reply to Re: Is this an efficient way check for certain conditions? by htoug
in thread Is this an efficient way check for certain conditions? by Zecho

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.