While I'm not among them, there are purists of structured programming who would advise against such short circuits as next, and last.

Those purists probably don't really understand what structured programming is really about and want to make it a bureaucratic straight jacket.

I remember that one of my CS professors once chastised me for having written a function or procedure (I can't remember which language it was, most probably either C or Pascal) in which I was returning early out of the function if a certain condition was met (or not met, whatever), saying me that this was a form of hidden goto (he had introduced Dijkstra's famous "Goto considered harmful" piece just a week or two before). I still received a fairly good mark, but I really felt at the time it was a ridiculous point.

I was quite happy, years later, to read somewhere in the Camel Book that programming is often building a decision tree and that it makes sense to discard early special cases, rather than having a deeply nested if/then/elsif/else conditional. Quite often, using next or last can also improve significantly the performance and the readability.

I would strongly suspect that Perl is not the right language for such purists. Let them write ten times more code-lines with A*a or Ja*a. (OK, sorry, I don't want to introduce a language flame war, but I replaced yesterday a 1500++ lines shell script with less than 20 lines Perl script, and it works better).


In reply to Re^2: regex 1st match only by Laurent_R
in thread regex 1st match only by ArifS

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.