If you want N of something, using an array to store them suggests itself to me.... but not to you! Updated to be more in line with OP.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $|++; my $numOfHashes = 5; my $hashref = { '6712' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6712' }, '6582' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6582' }, '6282' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6282' }, '6462' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6462' }, '16712' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6712' }, '26582' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6582' }, '36282' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6282' }, '46462' => { 'IP_ADDRESS' => '1.2.3.44', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6462' }, '96182' => { 'IP_ADDRESS' => '9.0.0.0', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000000000000 +000000000000', 'CSX_ID' => '6182' } }; my $keys = keys %{$hashref}; my $worker; print "Original Hash Keys: $keys\n"; my $i=0; foreach my $key ( keys %{$hashref} ) { $worker->{$i++}{$key} = $hashref->{$key}; $i %= $numOfHashes; } print Dumper($worker);

Output:

Original Hash Keys: 9 $VAR1 = { '4' => { '36282' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6282', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '00000000000000000 +0000000000000000000000' } }, '1' => { '6582' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6582', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000 +000000000000000000000' }, '46462' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6462', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '00000000000000000 +0000000000000000000000' } }, '3' => { '6282' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6282', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000 +000000000000000000000' }, '96182' => { 'IP_ADDRESS' => '9.0.0.0', 'CSX_ID' => '6182', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '00000000000000000 +0000000000000000000000' } }, '0' => { '16712' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6712', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '00000000000000000 +0000000000000000000000' }, '6462' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6462', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000 +000000000000000000000' } }, '2' => { '6712' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6712', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '000000000000000000 +000000000000000000000' }, '26582' => { 'IP_ADDRESS' => '1.2.3.44', 'CSX_ID' => '6582', 'IPV6' => '0', 'IP_ADDRESS_BIN' => '00000000000000000 +0000000000000000000000' } } };
1 Peter 4:10

In reply to Re: How can I split a hash into other N hashes by GotToBTru
in thread How can I split a hash into other N hashes by ataX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.