perl 小工具 -- 行列转置小脚本

行列转置的小脚本

#!/usr/bin/perl -w
use strict;


my %out;
open IN, $ARGV[0] || die $!;
while(<IN>){
    chomp;
    my @a = split /\t/, $_;
    for (my $i=0;$i<@a;$i++){
        $out{$i}{$.} = $a[$i];
    }
}
close IN;

foreach my $k (sort {$a<=>$b} keys %out ){
    my $out;
    foreach my $d (sort {$a<=>$b} keys $out{$k}){
        $out .= "$out{$k}{$d}\t";
    }
    $out =~ s/\t$//g;

    print "$out\n";
}

__END__
sxliulian2009@126.com
    原文作者:正踪大米饭儿
    原文地址: https://www.jianshu.com/p/e0f98bbf8b87
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞