Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: making 3 files into one

by CountZero (Bishop)
on Feb 17, 2009 at 22:26 UTC ( [id://744579]=note: print w/replies, xml ) Need Help??


in reply to making 3 files into one

Will handle arbitrarily large files with minimal memory use:
use strict; open my $FILE1, '<', 'my/input/file1' or die "Could not open FILE1: $! +"; open my $FILE2, '<', 'my/input/file2' or die "Could not open FILE2: $! +"; open my $FILE3, '<', 'my/input/file3' or die "Could not open FILE3: $! +";; open my $FILE4, '>', 'my/output/file' or die "Could not open FILE4: $! +"; while (my $file1 = <$FILE1>) { my $file2 = <$FILE2>; my $file3 = <$FILE3>; chomp $file1; chomp $file2; print $FILE4, "$file1 $file2 $file3" or die "Could not print to FI +LE4"; }
Update: We assume that each file has the same number of lines.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-20 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found