App-colalign
view release on metacpan or search on metacpan
#!/usr/bin/perl
#use 5.001 ;
use strict ;
use warnings ;
use feature qw[ say ] ;
use App::colalign ; # $App::colalign::VERSIONãå©ç¨ãããããéçºä¸ã¯ãæ¢ã«ã¤ã³ã¹ãã¼ã«æ¸ã¿ã®ãã®ã使ã£ã¦ãã¾ãã®ã§ãæå³ãã«ããåä½ã«ãªãã ããã
use Getopt::Std ;
use List::Util qw[ minstr maxstr all any min max ] ;
use Term::ANSIColor qw [ :constants ] ; ${Term::ANSIColor::AUTORESET} = 1 ;
use Time::HiRes qw[gettimeofday tv_interval] ;
my $time_start ;# = [ gettimeofday ] ;
BEGIN { $time_start = [ gettimeofday ] }; # BEGIN UNITCHECK CHECK INIT # å使éã®æ£ç¢ºæ¸¬å®ã®ããBEGINã§å²ãã ã
getopts 'a:c:i:I:C:1:' , \my%o ;
$o{a} ||= 1 ; # æä½éãä½åã®åããåºåè¡ã«å
¥ããã
$o{c} //= '#n#'; # ä½åãªæ¹è¡æåããã©ããªæååã«ç½®ãæããããã
$o{i} //= "\t" ; # å
¥åã®åã®åºåãæå
$o{I} //= '#t#' ; # ä½åãªååºåãæåããã©ããªæååã«ç½®ãæãããã
# $o{C} ; # ãããåã®æ°ãå¤ãããå ´åã«ãä½åç®ã«ä½åãªåãé£çµãããã(åã®é çªã¯å¤ããªã)ã
my $o1 = $o{1} // '' ; # ãã人工çãªå¯¾ç
my $L = 0 ; # åºåè¡æ°
my @mL = () ; # 夿´ããåºåã¯ç¬¬ä½è¡ç®ã§ãã£ããã
my @F ; # 仮容å¨ãåè¡ãèªãã æã®ãã°ãã°ãã«ãããã£ã¼ã«ã
my @G ; # æ¬å®¹å¨ãã¾ã åºåãã¦ããªããã£ã¼ã«ã ;
my $bk ; # 空è¡ãã©ã°
LOOP :
while ( <> ) {
chomp ;
@F = split /$o{i}/o , $_ , -1 ; # 空è¡ãæ¥ãå ´åã®ãã¨ã¯ãã¾ã èãã¦ããªãã(!)
do { $bk = 1 ; next } if @F == 0 ; # 空è¡ã®å¦çã2ç®æã«åããã¦ããªããã¼(#1)ã
next if @F == 1 && exists $o{1} && $F[0] =~ m/$o1/o ; # 1åãããªãå ´åãããããã¦ãã¾ã£ããåºåå¦çã
next if @G == $o{a} && @F >= 2 ; # @G == $o{a} ãæãç«ã£ã¦ããå ´åãæ³å®ãã¦ããã
if ( @G ) { splice @G , -1 , 1 , "$G[$#G]$o{c}$F[0]" , @F[1..$#F] ; push @mL , $L+1 } else { @G = @F } # ããã§ã¯@Gã@Fã¨çµåã
@F = () ; # æ¬å®¹å¨ã«æ ¼ç´ä½æ¥ããã®ã§ã仮容å¨ã¯ç©ºã«ã
goto LOOP if @G <= $o{a} ; # -a ã§æå®ããæ°ã«æºããªãå ´åã§ããä¸åº¦ä¸è´ããå ´å(次è¡ã1åã§ç¡ãããè¦ã)ãcontinueãããã¯ãå®è¡ããã«whileã®å
é ã¸ã
} continue {
do { $L ++ ; say join "\t", @G } ; # ã²ã¨ã¾ããåºãã¹ããã®ãåºåã
do { $L ++ ; say '' ; $bk = 0 } if $bk ; # 空è¡ã®å¦çã2ç®æã«åããã¦ããªããã¼(#2)ã
do { @G = @F ; @F = () } ; # 仮容å¨ããæ¬å®¹å¨ã¸ã
}
do { $L ++ ; say join "\t", @G } if @G ;
END {
my $time_elapsed = sprintf '%.4f', tv_interval ( $time_start , [ gettimeofday ] ) ;
my $end ;
$end = do { $. //= 0 ; "$. lines read. $L lines output. " } ;
$end .= "${time_elapsed}s. ($0)" ;
say STDERR BOLD FAINT ITALIC $end ;
my ($mL1, $mL2) = ( (min @mL) , (max @mL) ) ;
say STDERR BOLD FAINT ITALIC "Modified output lines : " . scalar @mL , " ($mL1-$mL2)" ;
}
sub VERSION_MESSAGE {}
sub HELP_MESSAGE {
use FindBin qw[ $Script ] ;
$ARGV[1] //= '' ;
open my $FH , '<' , $0 ;
while(<$FH>){
s/\$0/$Script/g ;
print $_ if $ARGV[1] eq 'opt' ? m/^\ +\-/ : s/^=head1// .. s/^=cut// ;
}
close $FH ;
exit 0 ;
}
=encoding utf8
=head1
$0 -a NUM [FILE]
( run in 0.485 second using v1.01-cache-2.11-cpan-56fb94df46f )