In order to incorporate others' solutions into your code I have to ignore the nonsensical HERE doc usage. It doesn't make sense to print << "CTHULU"; at the end of your script, while the HERE doc's end tag appears as line 3.

As several posts here suggested, increment a counter and use the modulus operator. Incorporating it into your code could nominally be as simple as this:

my $modulator = 0; foreach (@fs_list) { print qq{<div class="row-fluid hideInIE8 data">\n} unless $modulator++ % 6; my ($up) = $_->{usepercent} =~ m/(\d+)\%/; print qq(\t\t<div class="span2" onTablet="span4" onDesktop="sp +an2">\n); print qq(<div class="circleStatsItemBox NSBlue">); print qq(<div class="header">$_->{fsname}</div>); print qq(<span class="percent">percent</span>); print qq(<div class="circleStat">); print qq(<input type="text" value="$up" class="widget"/>); print qq(</div>); # ...and so on... }

This is an idiom that comes up frequently in programming when the goal is to do something every n-th step. And it's not unique to Perl. It turns out that this is a pretty "good idea". Higher Order Perl says this, regarding "Good Ideas":

There aren’t too many ideas that are both good and simple. The few that we have are used everywhere.

This is one of those good and simple ideas that gets used everywhere.


Dave


In reply to Re: foreach loop by davido
in thread foreach loop by Anonymous Monk

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.