I agree your question is badly posed; I, at least, don't really understand the details.

See How to ask better questions using Test::More and sample data. You might start with something like

use strict; use warnings; use Test::More 'tests' => <number of tests>; use Test::NoWarnings; # adds 1 test use Data::Dumper; # for debug my @al = (...); my @distribution = ( 3, 4, 5, 5, 6, 6, 8, 10, ); my $ar_expected_output = ( [ ... ], [ ... ], ... ); my $ar_got_output = distribute(\@al, \@distribution); is_deeply $ar_got_output, $ar_expected_output; exit; # subroutines ############################################# sub distribute { my ($ar_input, # array ref.: input array $ar_distribution, # array ref.: distribution to output arrays ) = @_; my @output; ... return \@output; }
Construct the output arrays first and test the process. Once you have the output arrays constructed, it should be fairly straightforward to output them to files.

See also Short, Self-Contained, Correct Example and Perl Data Structures Cookbook.

See perlintro for basic file I/O stuff, open and perlopentut for more advanced stuff.

Maybe also see I know what I mean. Why don't you?


Give a man a fish:  <%-{-{-{-<


In reply to Re: splitting 2D array into chunks by AnomalousMonk
in thread splitting 2D array into chunks by corfuitl

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.