in reply to Generate list with array elements repeated x times

Calling return ends the foreach loop. Replace the loop with the marked line (and try the whole script to test):
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; sub date_list { my @mults =qw( 2010-01-01 2010-01-02 2010-01-03 ); return map { ($_) x 10 } @mults; # <--- HERE } say for date_list('2014-01-01', '2014-01-10');
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Generate list with array elements repeated x times
by Anonymous Monk on Oct 16, 2014 at 20:47 UTC

    Excellent. Your code did just what I needed to get the desired output. But as my code makes a list of dates depending on variable start and end dates, I needed to use


    my @mults = split(' ', $dates); return (("$first") x 10), (map { ($_) x 10 } @mults), (("$last") x 10) +;

    ....to get each of the elements listed in the desired form. Just searching on, "use variables with qw()" pointed me to split. I knew it was simple. Now I can see the next tree behind this one in the forest. Thanks choroba.

      No problem. You can simplify it to
      return map { ($_) x 10 } $first, @mults, $last
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ