Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Pushing Element Multiple Times to Array

by Anonyrnous Monk (Hermit)
on Feb 13, 2011 at 09:15 UTC ( #887840=note: print w/ replies, xml ) Need Help??


in reply to Pushing Element Multiple Times to Array

while (my ($var, $cnt) = each %hash) { push @flat, ($var) x $cnt; }

Unlike with the respective map solution, this allows you to use self-documenting variable names, and it also scales better performance-wise (both memory and execution time).  (Some people still prefer to use map — presumably because it allows them to show they've grasped basic functional programming concepts (or so, I guess).)


Comment on Re: Pushing Element Multiple Times to Array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2013-05-24 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (515 votes), past polls