in reply to Chopping a file into pieces
Not sure if it works perfectly everytime, but it should achieve roughly what you want (otherwise, tweak at will ;).use strict; use warnings; @ARGV == 2 or die("Usage: $0 FILE PARTS\n"); my($file,$partsize) = @ARGV; my $filesize = -s $file or die("ack: $!"); my $div = $filesize / $partsize; my $cnt = 0; open(my $fh, $file) or die("ack: $!"); { local $/ = \$div; while($filesize > 0) { open(my $chunk, ">${file}.chunk$cnt") or die("ack: $!"); print $chunk scalar <$fh>; $filesize -= $div; $cnt++; } }
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Chopping a file into pieces
by graff (Chancellor) on Jan 29, 2003 at 03:09 UTC |