App-matrixpack
view release on metacpan or search on metacpan
scripts/matrixpack view on Meta::CPAN
#!/usr/bin/perl
use 5.014 ; use strict ; use warnings ;
use Getopt::Std ; getopts '1ah/:' , \my%o ;
use Term::ANSIColor qw[:constants] ; $Term::ANSIColor::AUTORESET = 1 ;
use Scalar::Util qw[looks_like_number] ;
use FindBin qw[$Script] ;
BEGIN{
print STDERR BRIGHT_RED qq["$ARGV[0]" may be given as a file although it should consist of column numbers.\n] if -f $ARGV[0] ;
}
my @cols = split /[,\n\t]/, shift @ARGV , 0 ; # æå®ãããåã @cols ã«æ ¼ç´ãããã
do { print STDERR BRIGHT_RED "[$Script] Numbers is not specified: @cols\n" ; exit 1 } if grep {! looks_like_number $_ } @cols ;
do { print STDERR BRIGHT_RED "[$Script] Only 0 is specified: @cols\n" ; exit 1 } unless grep { $_ != 0} @cols ;
my $sep = $o{'/'} // "\t" ;
my @ca = @cols ; # @colsã使¥ç¨ã«æ ¼ç´ãããå¦çä¸ã«ä½¿ãããã
do{ select STDERR ; &HELP_MESSAGE } unless @cols ;
$o{h} ? & takehead : & packing ;
do { print "\n" for @ca } if $o{a} ;
exit 0 ;
sub takehead {
while ( <> ) {
my $c = shift @ca ;
do { last if $o{1} ; @ca = @cols ; $c = shift @ca } if ! defined $c ;
chomp ;
my @F = split /$sep/,$_,-1 ;
print join ( $sep , splice @F , ($c>0?0:$c) , abs $c ) , "\n" ;
}
}
sub packing {
my $ind = 0 ;
while ( <> ) {
$ind = shift @ca if $ind == 0 ;
do { last if $o{1} ; @ca = @cols ; $ind = shift @ca } if ! defined $ind ;
do { print "\n" ; redo } if $ind == 0 ;
$ind -- ;
chomp $_ ;
print $_ ;
print $ind ? (eof () ) ? "\n" : $sep : "\n" ; # () ãã¤ããã¨ã§@ARGV ã®åãã¡ã¤ã«ã®EOFã®æ¤åºã§ã¯ç¡ãã¦ãå
¨é¨ã®æå¾ãæ¤åºã
}
}
## ãã«ãã¨ãã¼ã¸ã§ã³æ
å ±
BEGIN {
$Getopt::Std::STANDARD_HELP_VERSION = 1 ;
our $VERSION = 0.00_14 ;
# æå㯠0.21 ãç®å®ã¨ããã
# 1.00 以ä¸ã¨ããå¿
è¦æ¡ä»¶ã¯è±èªçã®ãã«ãããã¡ãã¨åºããã¨ã
# 2.00 以ä¸ã¨ããå¿
è¦æ¡ä»¶ã¯ãã¹ãã³ã¼ããå«ããã¨ã
# 0.00_12 : ãªãã·ã§ã³ãå¤ããã-rã使ããã-1ã使ãããã«ãããæå¾ãæ¹è¡ã§çµäºããªããã¨ããããã¨ãæå¶ã
# 0.00_13 : åçªå·ã«0ãæå®ãããå ´åã«å¯¾å¿ãæå³ã®ç¡ãæå®ã«è¦åãã¨ã©ã¼ãåºãããã«ããã
# 0.00_14 : åºåãæåã夿´ã§ããããã«ããã
}
sub HELP_MESSAGE {
use FindBin qw[ $Script ] ;
$ARGV[1] //= '' ;
open my $FH , '<' , $0 ;
while(<$FH>){
s/\$0/$Script/g ;
print $_ if s/^=head1// .. s/^=cut// and $ARGV[1] =~ /^o(p(t(i(o(ns?)?)?)?)?)?$/i ? m/^\s+\-/ : 1;
}
close $FH ;
exit 0 ;
}
=encoding utf8
=head1
$0 [-1] [-h] num1,num2,num3...,numk < somefile
( run in 0.525 second using v1.01-cache-2.11-cpan-39bf76dae61 )