Here is a slight variation on GrandFather's solution that shows you how you could construct your array of @numbers by using a list repetition operator (see "x" in Multiplicative Operators) inside the map. It also shows you how to use an iterator to cycle round the list of breads. The iterator is a reference to a subroutine that returns the next element in the @breads array each time it is called ($breadsIter->()), resetting the element to zero whenever is has passed the end of the array.

use strict; use warnings; use 5.010; my $breadsIter = do { my $idx = 0; my @breads = qw{ w r i f i r w f }; sub { $idx = 0 if $idx > $#breads; return $breads[ $idx ++ ]; }; }; my @numbers = map { ( $_ ) x 3 } 4, 7, 11, 14; my $finalStr = join q{ }, map { $breadsIter->(), $_, $breadsIter->() } @numbers; say $finalStr;

The output.

w 4 r i 4 f i 4 r w 7 f w 7 r i 7 f i 11 r w 11 f w 11 r i 14 f i 14 r + w 14 f

I hope this is of interest.

Cheers,

JohnGG


In reply to Re: array and concatenate by johngg
in thread array and concatenate by redmustang

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.