zoukankan      html  css  js  c++  java
  • [ Perl ] 对文本文件进行行列翻转

    https://www.cnblogs.com/yeungchie/

    code

    #!/usr/bin/env perl
    #-----------------------------
    # Program  : reverseRowCol.pl
    # Language : Perl
    # Author   : YEUNGCHIE
    # Version  : 2021.09.01
    #-----------------------------
    use v5.10;
    use strict;
    use warnings;
    use List::Util qw/max/;
    
    my ($in,$out) = @ARGV;
    
    open IN,"< $in";
    my @array;
    push @array,[split] for <IN>;
    close IN;
    
    my $index = max(map { scalar @$_ } @array)-1;
    
    open OUT,"> $out";
    for my $i (0..$index){
        printf OUT "%s
    ",(join ' ',map { my @row = @$_; $row[$i] } @array);
    }
    close OUT;
    
    __END__
    

    example

    shell> cat txt
    00 01 02 03 04
    05 06 07 08 09
    10 11 12 13 14
    15 16 17 18 19
    20 21 22 23 24
    
    shell> ./reverseRowCol.pl txt txt1
    
    shell> cat txt1
    00 05 10 15 20
    01 06 11 16 21
    02 07 12 17 22
    03 08 13 18 23
    04 09 14 19 24
    
  • 相关阅读:
    代理模式
    面向对象设计原则
    砝码破碎
    阿里EasyExcel使用
    IBM的OpenJ9
    java反射 (复习)
    DecimalFormat保留小数
    Object类
    SQLMAP用法
    SQL盲注之时间注入
  • 原文地址:https://www.cnblogs.com/yeungchie/p/15212956.html
Copyright © 2011-2022 走看看