I like this sort of pattern (update: maybe "style" would be a better word to use here than "pattern"):

c:\@Work\Perl\monks>perl -wMstrict -le "my @SlectedColumns = (9, 7, 6, 0, 5, 0, 4, 3, 2, 0, 1, 9, 9); my $end_index = 10; ;; COLUMN: for my $col (@SlectedColumns[1 .. $end_index]) { next COLUMN unless $col != 0; print qq{do something with col $col}; } " do something with col 7 do something with col 6 do something with col 5 do something with col 4 do something with col 3 do something with col 2 do something with col 1
An  if (COND) { ... } structure with its messy indentation and visual presentation is avoided, and cyclomatic complexity is reduced.

Update 1: In my experience, this pattern turns up quite often in a context like:

use constant RX_COMMENT => qr{ ... }xms; ... ... sub is_valid { my ($string, ) = @_; return $string =~ RX_COMMENT ? 0 : $string =~ RX_BLANK_STRING ? 0 : $string =~ RX_VALID_LINE ? 1 : die "invalid: '$string'" # default ; } ... ... LINE: while (my $line = <$fh>) { next LINE unless is_valid($line); do_something_with_known_valid($line); do_something_else_with($line); ... } # end while LINE

Update 2: This is my 4000th writeup!


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


In reply to Re: loop array excluding some elements by AnomalousMonk
in thread loop array excluding some elements by IB2017

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.