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

use strict; use warnings; #OPEN FILE A.txt FOR APPENDING (CHECK FOR FAILURES) open ( FOO, ">>", 'A.txt' ) or die "Could not open file A.txt: $!"; #OPEN FILE B.txt for READING (CHECK FOR FAILURES) open ( BAR, "<", 'B.txt' ) or die "Could not open file B.txt: $!"; #READ EACH LINE OF FILE B.txt (BAR) and add it to FILE A.txt (FOO) while ( my $line = <BAR> ) { print FOO $line; }
HTH

-enlil

Replies are listed 'Best First'.
Re^2: How can I concatenate two files?
by terra incognita (Pilgrim) on Sep 02, 2004 at 20:33 UTC
    What about?
    print FOO <BAR>;
    Or is this bad for some reason.

      Doesn't that load up the entire file into memory? It could be a problem with bigr files.

Re^2: How can I concatenate two files?
by ikegami (Patriarch) on Apr 12, 2005 at 21:20 UTC

    That's not portable. You should use binmode on your handles.

    Also, <BAR> could return an arbitrary long line. You can limit the size of that line using $/ = \4096;.