Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: split file into smaller chunks

by davorg (Chancellor)
on Jul 17, 2009 at 08:57 UTC ( #780967=note: print w/ replies, xml ) Need Help??


in reply to split file into smaller chunks

I don't think this is necessarily quicker. But it only ever has one filehandle open.

{ local $/ = "\\/n"; my $file_no = 1; open my $fh, '>', "file$file_no" or die $!; while (<>) { print $fh, $_; unless ($. % 1000) { close $fh; $file_no++; open $fh, '>', "file$file_no" or die $!; } } }
--

See the Copyright notice on my home node.

Perl training courses


Comment on Re: split file into smaller chunks
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://780967]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-07-05 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls