Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://780967]
[erix]: I would have thought that alignment is an important optimizing consideration for most (large) software -- I know it is for postgres...
[marto]: "left a bit... left a bit.... left a bit.... too far :("
[erix]: and whence the Host in "Host C" Corion?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-04-25 09:53 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (449 votes). Check out past polls.