A COBOL programmer programs COBOL in every language

I think one of the rules of Perl programming (and programming in any language) is to use the language specific features. Perl is optimized for array and list operations, and it is always better to use the Perl specific features like push and pop instead of some index twiddling. Of course, this requires knowledge of the builtin functions and operators, and such knowledge only comes with the time.

Regarding your question about placing the if, I say, that is the responsibility of the programmer. I always place the if according to what the current routine / block is supposed to do. If it is only parameter validation or error checking, the if is postfixed, but if the purpose of the whole subroutine is validation, the if might become a prefix. Some fictional example of my "good" coding style :

sub checkLine { # returns an (error) string that describes # what the line contained. # I place the if behind the return because # if I look at the code, I have an error message # and want to know what caused this message. return "! found at start of line." if /^!/; return "Line too short" if !/.{5,}/; return ""; }; if {/BEGIN/i) { # here I use a prefixed "if", because a longer block follows. };

From all RE engines I have looked at (the Perl RE engine is not with those ;), they implement character matching by using a lookup table of "matching" characters, so it should not make a speed difference whether you use /i or not. I might be wrong for Perl though ...


In reply to Good coding practices / Case Insensitive RE matching by Corion
in thread Good coding practices by Ovid

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.