#!/usr/bin/env perl
use strict;
use warnings;
my %data = qw{a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9};
my $N = $ARGV[0];
my $i = 0;
my %work;
$work{(($i += 1) % $N) + 1}{$_} = $data{$_} for keys %data;
use Data::Dump;
dd \%work;
####
$ pm_example.pl 2
{
1 => { a => 1, b => 2, f => 6, i => 9 },
2 => { c => 3, d => 4, e => 5, g => 7, h => 8 },
}
####
$ pm_example.pl 3
{
1 => { c => 3, d => 4, e => 5 },
2 => { b => 2, h => 8, i => 9 },
3 => { a => 1, f => 6, g => 7 },
}
####
$ pm_example.pl 4
{
1 => { d => 4, g => 7 },
2 => { a => 1, e => 5, i => 9 },
3 => { c => 3, h => 8 },
4 => { b => 2, f => 6 },
}