in reply to How do you create a tab delimited txt file from two files?

#! perl -slw use strict; open ONE, '<', $ARGV[0] or die $!; open TWO, '<', $ARGV[1] or die $!; until( eof( ONE ) ) { chomp( my $one = <ONE> ); chomp( my $two = <TWO> ); print "$one\t$two"; } close ONE; close TWO; __END__ c:\test>junk11 file1 file2 one 1 two 2 three 3 four 4 five 5 six 6 seven 7 eight 8 nine 9 ten 10

Replies are listed 'Best First'.
Re^2: How do you create a tab delimited txt file from two files?
by k_manimuthu (Monk) on Jul 29, 2010 at 08:06 UTC

    I consider the file1 and the file2 contents are equal numbers

    use strict; use warnings; ### open the first file and store in to a array format open (F1, "file1.txt") || die "Cannot open the input file : $!"; my @file1=<F1>; close (F1); ### open the second file and store in to a array format open (F2, "file2.txt") || die "Cannot open the input file : $!"; my @file2=<F2>; close (F2); my @file3; ### process each element and store the file1 and the corresponding ### value in second file in another one array for (my $i=0; $i<=$#file1; $i++) { chomp($file1[$i]); push @file3, "$file1[$i]\t$file2[$i]"; } ### print the array in a output file open (FOUT, ">Concat.txt") || die "Cannot create the output file"; print FOUT @file3; close (FOUT);