Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Loading multiple identical variables in array with multiplication variable

by johngg (Canon)
on Sep 24, 2014 at 22:06 UTC ( #1101881=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1101881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2019-05-24 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (150 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!