Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Split a binary file in pieces

by ZJ.Mike.2009 (Scribe)
on Mar 10, 2010 at 05:54 UTC ( [id://827700]=note: print w/replies, xml ) Need Help??


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

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; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-28 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found