That's not the hard part. The hard part is doing "the right thing" if the files do not have the same number of lines. Oh, and if these were arrays - you might want to look at tye's Algorithm::Loops - specifically mapcar. FWIW - you can read a file into an array pretty easily using the syntax my @array = <FILEHANDLE>; # just remember you have slurped the entire file into memory.
#!/usr/bin/perl use strict; use warnings; my $file1 = $ARGV[0] || 'file1.txt'; my $file2 = $ARGV[1] || 'file2.txt'; open (FILE1, '<', $file1) or die "Unable to open $file1 for reading : +$!"; open (FILE2, '<', $file2) or die "Unable to open $file2 for reading : +$!"; while ( <FILE1> ) { chomp; my $foo = <FILE2>; $foo = 'N/A' if eof FILE2; print join "\t" , $_ , $foo; print "\n"; } while ( <FILE2> ) { chomp; print join "N/A\t$_\n"; }
Cheers - L~R
In reply to Re: Combining Lines from Two Docs into Another
by Limbic~Region
in thread Combining Lines from Two Docs into Another
by Neuroactive
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |