Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How can I split a hash into other N hashes

by oiskuu (Friar)
on May 13, 2014 at 17:47 UTC ( #1085935=note: print w/ replies, xml ) Need Help??


in reply to How can I split a hash into other N hashes

Do you actually require splitting the hash? Partitioning the keys might suffice in many situations.

In any case, using part is one option.

use List::MoreUtils qw(part); use constant NWAYS => 3; my $i; #my @AoA = part { $i++ % NWAYS } keys %hash; my @AoH = map +{map {$_ => $hash{$_}} @$_}, part { $i++ % NWAYS } keys + %hash;
Update. Much cleaner with key/value slices[*] (untested):
use 5.020; my @AoH = map +{ %hash{@$_} }, part { $i++ % NWAYS } keys %hash;


Comment on Re: How can I split a hash into other N hashes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-07-05 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls