Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How to concatenate the contents of two files?

by ccn (Vicar)
on Sep 02, 2004 at 20:14 UTC ( [id://388085]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found