in reply to Loading multiple identical variables in array with multiplication variable
Another variation using an inner map instead of the list multiplier and a list of hashrefs as the template.
$ perl -Mstrict -Mwarnings -E ' my @array = map { my( $key ) = keys %$_; map $key, 1 .. $_->{ $key }; } { A => 3 }, { T => 4 }, { C => 2 }, { G => 5 }; say for @array;' A A A T T T T C C G G G G G $
I hope this is of interest.
Update: Another couple of variants:-
$ perl -Mstrict -Mwarnings -E ' my @array = map { ( keys %$_ ) x do { my( $v ) = values %$_; $v } } { A => 3 }, { T => 4 }, { C => 2 }, { G => 5 }; say for @array;' ...
$ perl -Mstrict -Mwarnings -E ' my @array = map { my( $k, $v ) = each %$_; ( $k ) x $v; } { A => 3 }, { T => 4 }, { C => 2 }, { G => 5 }; say for @array;' ...
Cheers,
JohnGG
|
|---|