Run and results:use strict; use warnings; my( %file, $idx, %cat,$x); $idx=1; # Start at 1 to avoid using the //= o +perator while (<>){ # read all files in @ARGV chomp; my ($c,$val)=split; # Separate the category from the valu +e next unless $c; # Skip blank lines $file{$ARGV} ||= $idx++; # Increment $idx for each new file $cat{$c}[ $file{$ARGV} ] = $val; # Save in $cat{Category}[FileIdx] } print "\t",map ({"$_\t"} sort keys %file),"\n"; # List of files my @FileIndexes = map {$file{$_}} sort keys %file; for my $k (sort keys %cat){ print "$k\t",map({(defined($x=$cat{$k}[$_])?$x:"")."\t"} @FileIndexes),"\n"; }
update:Noticed you were "new to perl", so I added comments, and simplified a bit$ perl test-tab1.pl test-tabd* test-tabdata.txt test-tabdata2.txt test-tabdata2.txt~ A 12 33 9 B 152 221 333 C 123 423 444 D 456 43 555 E 99
I hope life isn't a big joke, because I don't get it.
-SNL
In reply to Re: simple table join script
by NetWallah
in thread simple table join script
by slavailn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |