in reply to Re: Split a binary file in pieces
in thread Split a binary file in pieces

I'm learning Perl. Thanks for the code. But how do we join the split pieces together? Thanks :)

Replies are listed 'Best First'.
Re^3: Split a binary file in pieces
by Anonymous Monk on Mar 10, 2010 at 04:47 UTC
    Write out how you would do it in words, then translate words into code

      You're right :) I'm thinking sometimes because the Perl community is too kind and helpful, I'm just tempted to become very very lazy :)

      Anyway I tried translating words into code and came up with the following ugly code, which seems to be working. But I know it's ugly :)

      use strict; use warnings; $/ = \20_000_000; #I've just split a 20-meg file open my $f1, "<", '1' or die $!; # piece 1 is named 1 binmode $f1; open my $f2, "<", '2' or die $!; # piece 2 is named 2 binmode $f2; while(my $x = <$f1>){ while(my $y = <$f2>){ open my $out, ">", "outfile" or die $!; binmode $out; print $out $x.$y; } }

      UPDATE: tried optimizing a few lines. It looks a little cleaner

      use strict; use warnings; $/ = \20_000_000; #I've just split a 20-meg file into 2 pieces open my $f1, "<", '1' or die $!; piece 1 is named 1 binmode $f1; open my $f2, "<", '2' or die $!; # piece 2 is named 2 binmode $f2; while(defined(my $x = <$f1>) && (my $y = <$f2>)){ open my $out, ">", "outfile" or die $!; binmode $out; print $out $x.$y; }