Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Merging text file

by aitap (Deacon)
on Sep 06, 2012 at 17:40 UTC ( #992156=note: print w/ replies, xml ) Need Help??


in reply to Merging text file

You don't need to read the whole file in the memory. Program will not work if the files become very big. Using Tie::File (or even DBD::CSV) to work with files is a good practice. Anyway, this is an example how to work with your files line-by-line:

use warnings; use strict; open my $first, "<", "first.txt" || die "first.txt: $!\n"; # three-argument form of open is safer # scalar variables as filehandles are more modern than barewords open my $second, "<", "second.txt" || die "second.txt: $!\n"; while (! eof $first && ! eof $second) { # while both filehandles can b +e read chomp (my $fline = <$first>); # you can read the line and chomp at the same line chomp (my $sline = <$second>); print "${fline},${sline}\n"; } close $first; close $second;
(tested only syntax).
Sorry if my advice was wrong.


Comment on Re: Merging text file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2014-07-31 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (251 votes), past polls