in reply to Re: How to concatenate the contents of two files?
in thread How to concatenate the contents of two files?
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.
|
|---|