in reply to How to concatenate the contents of two files?

open A, '>> A.txt' or die $!; open B, '< B.txt' or die $!; print A <B>;

perldoc perlopentut

Replies are listed 'Best First'.
Re^2: How to concatenate the contents of two files?
by Aristotle (Chancellor) on Sep 02, 2004 at 20:37 UTC

    With an eye on avoiding globals, with Two-arg open() considered dangerous in mind, and avoiding to slurping the entire input file or breaking it into lines when you're not going to need it split up that way anyway:

    my $infile = "A.txt"; my $outfile = "B.txt"; open my $in_fh, '<', $infile or die "Couldn't open $infile for reading: $!\n"; open my $out_fh, '>>', $outfile or die "Couldn't open $outfile for appending: $!\n"; { local $/ = \65536; # read 64kb chunks while ( my $chunk = <$in_fh> ) { print $out_fh $chunk; } }

    Makeshifts last the longest.