The 'perlintro' section of the documentation mentions this via the term 'post-condition'. Basically, control terms like while, if, foreach, unless can come after the execution portion, making the execution conditional. The "thing to do" doesn't have to be in a statement block (because you are setting up only ONE thing to do) and the conditional part after the control term doesn't need to be in parens. (Less clutter overall.) What else would you expect from a linguist who thought such contructs perfectly normal in speech and so why not in logic? So, you will see things like:

next if /^#/; last if /#{5,}/; warn "B-Fruit: '$_'\n" foreach grep { /^b/ } @fruits; build_acty_for_callout_at_sub_loc_hash( $fxhr, $previous_data_ar, \%acty_for_callout_at_sub_loc ) unless %acty_for_callout_at_sub_loc;

Personally, it annoys me to read a line of Perl and midway through the line, or almost at the end, find such a qualifier term. (All that thinking through of what is going to happen and then you read if SOME CRAZY CONDITION THAT PROBABLY WON'T HAPPEN;) So, my preference is to spread such statements over two lines, so that your eyes see early on the left side the critical pieces of the statement. Like so:

warn "B-Fruit: '$_'\n" foreach grep { /^b/ } @fruits;

This particular example is one I would usually avoid breaking over two lines! Generally, I have lines like this in my code for debugging purposes, and usually they are commented out except for times when I want the extra verbiage to stand out. For these special cases, I only have to comment out one line if I keep the construct to one line instead of two. :-)

A drawback with 'post-conditions' is that once you decide you would like to do two things instead of one, you must invert the construct back to the normal view, i.e.

foreach ( grep {/^b/} @fruits ) { print LOGFILE "Found B-Fruit '$_'\n; warn "B-Fruit: '$_'\n"; }

So at the end of the day, I believe you will find it is one of Damian's "Perl Best Practices" to avoid use of this construct except for super simple statements like  last unless @words


In reply to Re^6: setting up boolean parameters from keywords by ff
in thread setting up boolean parameters from keywords by rand0mmm

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.