in reply to Is this possible
There's not really any "correct" way. ...or maybe it's more accurate to say, there's no wrong way as long as it works and doesn't gobble all your memory in the process. ;)
Here is yet another way to do it:
use strict; use warnings; my @files = @ARGV; my %table; foreach my $filename (@files) { open my $infile, '<', $filename or die $!; while( <$infile> ) { chomp; next unless $_; my( $name, $val ) = split; push( @{$table{ $name }}, $val ); } } my @names = sort keys %table; my $output = join "\t", "NAME\t", @files; foreach my $entry ( @names ) { $output .= join "\t\t", "\n$entry", @{$table{$entry}}; } $output .= map { local $" = "\t\t"; "@{$table{$_}}\n"; } @names; print $output, "\n";
Usage: perl scriptname filename1 filename2
It doesn't bother to check to ensure that all files contain the proper number of entries. That could cause your columns to become misaligned, if for example, the second file doesn't contain an entry for Georgia.
Dave
|
|---|