... this could have been done via grep in clever ways ...

You may be thinking of something like:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @list = (rand(1), rand(1), rand(1)); dd \@list; ;; my $less = 1; for (@list) { $less = 0, last if $_ >= 0.5; } print 'for: all satisfy the condition' if $less; ;; my $any = grep { $_ >= 0.5 } @list; print 'grep: none fail the condition' if not $any; " [0.860137939453125, 0.796112060546875, 0.875457763671875] c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @list = (rand(1), rand(1), rand(1)); dd \@list; ;; my $less = 1; for (@list) { $less = 0, last if $_ >= 0.5; } print 'for: all satisfy the condition' if $less; ;; my $any = grep { $_ >= 0.5 } @list; print 'grep: none fail the condition' if not $any; " [0.134674072265625, 0.332855224609375, 0.4288330078125] for: all satisfy the condition grep: none fail the condition

Because grep must continue to grind through all remaining elements of the list even after it is determined that the overall condition has failed, I'm not sure I would consider this "clever." Quick and dirty, yes, and useful as such.

The for-loop approach has the advantage that it stops immediately when the overall condition is determined to have failed. The guts of List::MoreUtils  any() and  all() and their ilk are based on for-loops. An extra variable is a small price to pay.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Fall through loop by AnomalousMonk
in thread Fall through loop by b4swine

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.