1 #!/usr/bin/perl -w 2 use strict; 3 4 my @master_list = (); 5 6 readfile("f1.lst", \@master_list); 7 readfile("f2.lst", \@master_list); 8 readfile("f3.lst", \@master_list); 9 10 printf "%s | %s | %s\n", @{$_}[0..2] for(@master_list); 11 12 sub readfile { 13 my $filename = shift or die "Need filename.\n"; 14 my $listref = shift; # Listed pointed to is modified in place. 15 16 open my $file, "< $filename" or die "Can't open $filename: $!\n"; 17 18 my $header = <$file>; 19 20 my $c = 0; 21 local $_; 22 while(<$file>) { 23 $listref->[$c] ||= []; # use strict doesn't like auto-viv. 24 chomp; 25 # Compare the new value with the first value stored in the list. 26 # First value to be read in for any row is assumed to be 27 # correct. All subsequent values must match that first one. 28 unless(@{$listref->[$c]} and $_ != $listref->[$c][0]) { 29 push @{$listref->[$c]}, $_; 30 } else { 31 push @{$listref->[$c]}, ' '; 32 } 33 34 ++$c; 35 } 36 37 close $file or die "Can't close $filename: $!\n"; 38 } #### unless(@{$listref->[$c]} and $_ != $listref->[$c][0]) { push @{$listref->[$c]}, $_; } else { push @{$listref->[$c]}, ' '; }