Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

by oiskuu (Hermit)
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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085935]
[LanX]: YM: BTW learn to mute your humanity
[Your Mother]: Cumin? Now I want tacos...
[Eily]: there should be an option in grep for fuzzy order of the letters in the pattern
[Eily]: as in "I might have inverted two, but my eyes misread in the some order as my fingers mistype"
[LanX]: can't find a definition for the sound

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2017-03-27 17:00 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.