I've been meaning to figure out how to open an array of filehandles, so here's my opportunity. I Super Searched where title contains all of "open", "handles" and found Opening Multiple FileHandles w/ Simpler Code and FileHandle.

The following will create 3 output files, named 1.txt, 2.txt, 3.txt. You can change the 3 to 24 in the code.

use warnings; use strict; use FileHandle; my @filenames = map { $_ . '.txt' } 1 .. 3; my @handles = map { FileHandle->new($_, '>') } @filenames; while (<DATA>) { my @cols = split /,/; $handles[$cols[1]-1]->print($_); } __DATA__ 10234,1,34234,342,453,34535,3453,3464 12123,1,23432,4353,44645,45654,45645,657 2123345,2,35435,3453,454,56567,56756,567567 3234353,2,34534,4564,567567,56757,56575,24234 33453,3,45464,4564564,45645,645645,54564,56456

In reply to Re: to divide/split a file to small files. by toolic
in thread to divide/split a file to small files. by Anonymous Monk

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.