in reply to read column in perl

use strict; open IN1, "file1" or die $!; open IN2, "file2" or die $!; open OUT, ">output"or die $!; my @file1; my @file2; chomp, push @file1, $_ while <IN1>; chomp, push @file2, $_ while <IN2>; close IN1; close IN2; my $i = 0;$file1[$i] .= "\t".(join "\t", split '\s', $_), $i++ for @fi +le2 ; print "$_$/" for @file1; print OUT "$_\n" for @file1; __END__ a 1 6 11 b 2 7 12 c 3 7 13 d 4 8 14 e 5 9 23


Replies are listed 'Best First'.
Re^2: read column in perl
by dragonchild (Archbishop) on Mar 08, 2005 at 13:39 UTC
    You don't want to read the whole file in if you don't have to - that doesn't scale well to files that are larger than your physical RAM. (Swap space is so slooooow!)

    Furthermore, the following can be rewritten:

    my @file1; my @file2; chomp, push @file1, $_ while <IN1>; chomp, push @file2, $_ while <IN2>; ############## chomp(my @file1 = <IN1>); chomp(my @file2 = <IN2>);

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.