Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How can I concatenate two files?

by Enlil (Parson)
on Sep 02, 2004 at 20:01 UTC ( [id://388079]=note: print w/replies, xml ) Need Help??


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;.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found