in reply to Problem creating array

If you use a list on the left hand side of the x repetition operator, it generates a list, not a string:
push(@result, ($i) x $count[$i]);
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Problem creating array
by Subop (Acolyte) on Sep 16, 2009 at 14:34 UTC

    Man you guys are good. You wouldn't believe the mess of loops I had trying to solve this problem. Thanks for everyone's help!

      Even if you didn't know how to use "x" to do what you want, it's not messy to do it without "x".
      # With "x" for my $i (0..$#count) { push @result, ($i) x $count[$i]; }
      # Without "x" for my $i (0..$#count) { for (1..$count[$i]) { push @result, $i; } }