I have started learning perl and like to try out new things.
I have some problem in text processing. I have some text of the form,
0 1 2 3 4 5 6 7 8
Here's my new script to transpose a tab-delimited file. Change \t to your delimiter if you like.
#!/usr/bin/perl -anF/\t|\n/
$n = @F - 1 if !$n;
for $i (0..$n) {
push @{ $m->[$i] }, $F[$i];
}
END {
for $r (@$m) {
print join("\t", @$r), "\n";
}
}
or as a 104 character "one liner" (with apostrophe-backslash-newline-apostrophe added to avoid horizontal scrolling):
perl -anF'\t|\n' -e'$n=@F-1if!$n;for(0..$n){push@{$$m[$_]},$F[$_]}'\
'END{print map{join"\t",@$_,"\n"}@$m}'