Thread mehre dateien in eine kopieren
(15 answers)
Opened by mark05 at 2011-03-21 11:00
ungetestet:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 use warnings; use strict; open(my $fh_1, '>>:raw', 'file1.bin'); open(my $fh_2, '<:raw', 'file2.bin'); my $buffer; my $bufsize = 32768; my $copied; while (1) { $copied = read $fh_2, $buffer, $bufsize; last if ! $copied; print $fh_1 $buffer; } copy aus File::Copy berücksichtigt den open-Modus des Filehandles nicht, soweit ich weiß. Nachtrag: mehrere Dateien zu einer neuen cat'en: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 use warnings; use strict; my @binfiles = qw( file1.bin file2.bin file3.bin ); open(my $fh_out, '>>:raw', 'outfile.bin'); my $buffer; my $bufsize = 32768; my $copied; for my $file (@binfiles) { open(my $fh_in, '<:raw', $file); READDATA: while (1) { $copied = read $fh_in, $buffer, $bufsize; last READDATA if ! $copied; print $fh_out $buffer; } close($fh_in); } Editiert von FIFO: open mode $fh_1 auf >> geändert Editiert von FIFO: Nachtrag Last edited: 2011-03-21 11:50:22 +0100 (CET) Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"
|