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).)
|
---|