I used to believe that Perl 6 will have this feature. I know that Ruby does already. I suspect that it would be complex to add to Perl 5 given how complex the parsing logic is already.

What I don't like about the feature is that when the logic gets more complex, you need to completely take the loop apart and rewrite. The more complex you let it get before that rewrite happens, the more painful the rewrite is. But if you want to keep it as a one-liner now, then I suggest that you write it like this:

print "$_\n" for grep /pattern/, @arr;
(I find that clearer than using boolean operators. Yes, they work, but I have to think more about what the author is trying to do...YMMV though.)

UPDATE: I realized that I was unclear about something. Ruby does not have an inline form of the basic for loop like it does if, unless, while and until. But the ones that it does do inline it allows you to stack as many deep as you want.

UPDATE 2: My beliefs have changed in view of TheDamian's response...


In reply to Re: One-liners: Conditionals in Loops by tilly
in thread One-liners: Conditionals in Loops by David Caughell

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.