Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Merging text file

by aaron_baugher (Deacon)
on Sep 06, 2012 at 16:01 UTC ( #992129=note: print w/ replies, xml ) Need Help??


in reply to Re: Merging text file
in thread Merging text file

The larger the files are, the more likely that slurping them into arrays will be a bad idea. Since we have no reason to think that's necessary, and his example keeps them in the same order as fileA (which a hash would lose), it makes more sense to read them line-by-line:

#!/usr/bin/perl use Modern::Perl; open my $fa, '<', 'file1.txt' or die $!; open my $fb, '<', 'file2.txt' or die $!; while(<$fa>){ chomp; print "$_,", scalar <$fb>; }

Of course, since he wants a CSV file, he may need to watch out for commas or quoting in his data. If it has none of that, he's safe. If it does, he may be better off building the output file with something like Text::CSV.

Aaron B.
Available for small or large Perl jobs; see my home node.


Comment on Re^2: 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://992129]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-12-28 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls