This works much better :)
This splits the file into 2gb chunks, I have tested on about 25-30 iso's is have stored on my PC and it works great, though sometimes writing performance is a little bit slow. You can also change how many gb's you want to split it into by changing the iterator's value.
use strict;
use warnings;
files();
sub files {
foreach (@ARGV) {
print "processing $_\n";
open my $fh, '<', $_ || die "cannot open $_ $!";
binmode($fh);
my $num = '000';
my $iterator = 0;
split_file( $fh, $num, $_, $iterator );
}
}
sub split_file {
my ( $fh, $num, $name, $iterator ) = @_;
my $split_fh = "$name" . '.split';
open( my $out_file, '>', $split_fh . $num ) || die "cannot ope
+n $split_fh$num $!";
binmode($out_file);
while (1) {
$iterator++;
my $buf;
read( $fh, $buf, 32 );
print( $out_file $buf );
my $len = length $buf;
if ( $iterator == 67108864 ) { #split into 2gb chun
+ks
$iterator = 0;
$num++;
split_file( $fh, $num, $name );
}
elsif ( $len !~ "32" ) {
last;
}
}
}
Works pretty quickly! split almost 5gb in 4.4333 mins. I do see a decrease in performance sometimes, though other times it writes very quickly. Go ahead and test it on one of your iso's. What would be the most efficient read/write buffer?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.