http://www.perlmonks.org?node_id=795629


in reply to Problem creating array

I just used a foreach, because the x looked to be related to the problem, and it was the first and simplest thing that came to mind. You could do it shorter and more elegantly, but this works and is probably a little easier to read if you're still learning a bit.
my @count = (1,3,1,1,1,1,1,2,1,1,3,2); my @result; for (my $i=0; $i <= $#count; $i++) { foreach (1 .. $count[$i]) { push(@result, $i); } } print "\@count: @count\n"; print "\@result: @result\n";