#!/usr/local/bin/perl # transpose (replace tab-spaced columns by cr-spaced rows and vice-versa) # stuff all data into an associative array $first = 1; while (<>) { chop; @line = split; # make sure that all lines have same length if (!$first) { ($#line == $nw) || die " wrong line size: $#line != $nw"; } else { $first = 0; } $nw = $#line; $nl++; # line number foreach $i (0 .. $nw) { $data{$nl . "_" . $i} = $line[$i]; } } # read data out foreach $j (0 .. $nw) { @line = (); foreach $i (1 .. $nl) { $x = $data{$i . "_" . $j}; push (@line, $x); } $y = join("\t", @line); print "$y\n"; }