atancasis has asked for the wisdom of the Perl Monks concerning the following question:
However, this looks like a lot of code to do something this trivial. There must be some inherent Perl feature that I'm missing that accomplishes this. Probably something akin to the x operator which repeats a scalar X number of times, or array slicing, or something to that effect.my @flat = map { exp_arr($_, $hash{$_}) } keys %hash; sub exp_arr { my $var = shift; my $cnt = shift; my @arr; for ( my $i = 0; $i < $cnt; $i++ ) { push @arr, $var; } return @arr; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pushing Element Multiple Times to Array
by CountZero (Bishop) on Feb 13, 2011 at 09:53 UTC | |
Re: Pushing Element Multiple Times to Array
by perlchanter (Novice) on Feb 13, 2011 at 09:22 UTC | |
Re: Pushing Element Multiple Times to Array
by Anonymous Monk on Feb 13, 2011 at 09:13 UTC | |
by CountZero (Bishop) on Feb 13, 2011 at 09:54 UTC | |
Re: Pushing Element Multiple Times to Array
by Anonyrnous Monk (Hermit) on Feb 13, 2011 at 09:15 UTC | |
Re: Pushing Element Multiple Times to Array
by atancasis (Sexton) on Feb 13, 2011 at 09:54 UTC |