http://www.perlmonks.org?node_id=1024571


in reply to Re: Splitting a text file
in thread Splitting a text file

Thanks, daxim, it was instructive to me to figure out how the pieces fit together. One thing though, your Perl code as written will put only 999 lines into the first file. This can be fixed by replacing $. with ($.-1)

</the/file perl -MIO::File -ne' my $nr = 1+int(($.-1)/1_000); $handles[$nr] = IO::File->new(sprintf("%05dNR.txt", $nr), "w") unl +ess defined $handles[$nr]; $handles[$nr]->print($_); '