App-expskip
view release on metacpan or search on metacpan
do { say STDERR RED "Specify the parameter for `-T' such as `$0 -T 1m'." ; exit } if ! defined $arg ;
my $cmd = '' ;
do {
no warnings 'experimental::smartmatch' ;
$cmd = "seq 20 | $0" when '20' ; # -T 20 ã§ "expskip" ã« seq 20 ã®çµæãä¸ããã
$cmd = "seq 20 | $0 -f5" when 'f5' ; # -T f5 ã§ "expskip -f5" ãã·ãã¥ã¬ã¼ã
$cmd = "seq 20 | $0 -p0" when 'p0' ; # -T p0 ã§ "expskip -p0" ãã·ãã¥ã¬ã¼ã
$cmd = "$0 <(seq 4) <(seq 10)" when 'm2' ; # -T m2 ã§ãè¤æ°ã®ãã¡ã¤ã«ãä¸ããã
$cmd = "seq 1e6 | $0" when '1m' ; # -T 1m ã§ "expskip" ã« 100ä¸ã¾ã§ã®æ°ãä¸ããã
$cmd = "seq 1e5 | $0 -e0" when 'e0' ; # -T e0
$cmd = "seq 1e5 | $0 -f5" when 'f5' ; # -T f5
$cmd = "seq 100 | tr 0-9 A-H | $0 -: 'yellow green bold italic'" ; # -T ac ã§ãæ°å以å¤ã¨è¡çªå·ã®è²ã¥ããåæã«ãã¹ãã
$cmd = "seq 1e7 | $0" when 'E7' ; # -T E7 ã§ 1000ä¸ã¾ã§ã®æ°ãä¸ããããªããseq 1e7ã1e7+1ã®æ°ãä¸ããã
} for $arg ;
$cmd = join " " , $cmd , @ARGV [ $A0 .. $#ARGV ] ; # <-- @ARGV ã«'ã"ãããã¨æã£ãããã«åä½ããªãã§ãããã
say STDERR YELLOW BOLD "> $cmd" ;
system $cmd ;
exit ;
}
getopts "::2:b:e:f:tp:zA:B:T:",\my%o ; # <-- -T以å¤ã®ãªãã·ã§ã³ãèªã¿åãã(ãã ãå使¤è¨¼ã®ãããTã¯ããã«æ®ããã)
eval "use PerlIO::gzip;1" or die "Can't import PerlIO::gzip despite -z instruction. ($Script)\n" if $o{z} ;
sub lineOut ( $ ) ; # lineOutã®ãããªé¢æ°åããã¤ãã®ãã¡ãã©ããã使ãããã
sub eachFile ( $ ) ;
sub fitCheck ( $ ) ;
$| = 1 ; # <- æ¯åãã©ãã·ã¥(使ãããç¶æ³ãèããã¨å¤åããã§è¯ãã¨æãããã)
$o{b} //= 10 ; # åºæ°ã®æå®ãbase
$o{e} //= 2 ; # æåã¨æå¾ã®ããããä½è¡ãåºåããããEdge
$o{f} ||= 1 ; # éå§è¡ãæå®ããã0ã§ãundefã§ãå¤ã1ã«ãªãããã«ãããfrom
$o{A} //= 0 ; # åè´ããè¡ã®ä½è¡å¾ã¾ã§ããã«ç¶ãã¦åºåããã After
$o{B} //= 0 ; # åè´ããè¡ã®ä½è¡åã«ããã®ã¼ã£ã¦ç¶ãã¦åºåããã Before
my (@nums0, @nums) ; # ä½è¡ç®ã-bã¨-pã®æ©è½ã§åºåãããã«ã¤ãã¦ã®è¡çªå·ãä¿ç®¡ã0ã¯ãã¹ã¿ã¼ãæå³ããã
my $oc ; # åãã¡ã¤ã«ã§åºåããè¡ãæ°ããã
# (åºåãã)æ¸å¼ã®æå® : å颿°ã¯ãã©ããã1åã ãã®å¼æ°ã ãããããç¡åé
åã®[è¡çªå·,ãã®è¡ã®æåå]ã§ããã
sub lineOutFnc ( $ ) ; # lineOutã®ãããªé¢æ°åããã¤ãã®ãã¡ãã©ããã使ãããããã³ãã¬ã¼ã..ã¨è¨ãã°è¯ãããª.
sub lineOutColon ( $ ) { $oc++ ; $_[0][0], ":\t", $_[0][1] } # è¡çªå·ã«ã³ãã³(:) ãä»å ãã¦åºå
sub lineOutCouleur ( $ ) { $oc++ ; color($o{':'}) . "$_[0][0]:" . color('reset') . "\t", $_[0][1] } # G
sub lineOutBlunt ( $ ) { $oc++ ; $_[0][1] }
sub lineOutTime ( $ ) { sprintf("%02d:%02d:%02d\t", @{[localtime]}[2,1,0]), lineOutFnc $_[0] } # <- ããã ãlineOutFncãä¸ã«å«ãã
* lineOutFnc = ($o{':'}//'')eq"0"? * lineOutBlunt : (exists$o{':'}) ? * lineOutCouleur : * lineOutColon ;
* lineOut = $o{t}? *lineOutTime : * lineOutFnc ;
@nums0 = do {
my %t =(0=>['Inf'],1=>[1],2=>[1,2,4,8],5=>[1,2,5],7=>[1,1.5,2,3,5,7],8=>[1,1.5,2,3,5,8],9=>[1..$o{b}-1]) ;
do { say STDERR BOLD RED "-p should has a parameter in {0,1,2,5,7,8,9}" ; exit } if exists $o{p} && !defined $t{$o{p}} ;
my @t = @{$t{$o{p}//1}} ;
grep {$_ < $o{b} || $_ == 'Inf'} @t
} ;
& procFiles ; # è¤æ°ã®ãã¡ã¤ã«ãæ³å®ãã¦å¦çã
exit 0 ;
sub procFiles ( ) { # è¤æ°ã®ãã¡ã¤ã«ãæ³å®ãã¦å¦ç
my $files = @ARGV ;
do {
my $fileName = shift @ARGV ; # ãã¡ã¤ã«å
my $FH ; # ãã¡ã¤ã«ãã³ãã«
open $FH , "<" , $fileName or warn "File `$fileName' does not open." and next if defined $fileName ;
$FH = *STDIN if ! defined $fileName ;
binmode $FH , ":gzip(autopop)" if $o{z} ; # <-- autopop ã¨ã¯?
say UNDERLINE $fileName if $files >= 2 ; # ãã¡ã¤ã«ã2å以䏿å®ããã¦ãããããã¡ã¤ã«åã表示ããã
& eachFile ( $FH ) ;
} while @ARGV
}
sub eachFile ( $ ) { # 1åã®ãã¡ã¤ã«ã«å¯¾ããå¦ç(弿°ã¯ãã¡ã¤ã«ãã³ãã«ãSTDINã®å ´åãããã)
@nums = @nums0 ;
my $FH = $_[0] ;
my $ready ; # ãã®æ°ãæ£ãªãåºåãããâ ä»çµã¿ã¯ãããªã®è¯ãæ°ãªã©ã®ããªã¬ã¼ã«ãããä¸å®å¤ãæ ¼ç´ããã¦ã1ãã¤æ¸ãã
my @stockLines = () ; # ããã¤ãã®è¡ã®ãæååãæ ¼ç´ããã
$oc = 0 ; # åºåããè¡ã®æ°ãæ°ããã®ã§ããã§ãªã»ããã
# 1. æåã®æ¹ã¯ãã¾ãä¸å®éèªãã
do { while ( <$FH> ) { last if $. +1 >= $o{f} } } if $o{f} >= 2 ;
do { while ( <$FH> ) { push @stockLines , [ $. , $_ ] ; last if @stockLines >= $o{e} } } if $o{e} > 0 ;
print lineOut $_ for @stockLines ;
my $firstEnd = @stockLines ? $stockLines[-1][0] : 0 ; # æåã®æ®µéã§èªãã æå¾ã®è¡ã®è¡çªå·
# 2. æ¡ä»¶ã«ä¸è´ãããã®ã®ã¿åºåããã
while ( <$FH> ) {
push @stockLines , [ $. , $_ ] ; # pushã¨shiftã対ã«ãã¦FIFOã®ãããªä»çµã¿
my $theNext = shift @stockLines ;
$ready = fitCheck $$theNext[0] ? $o{A} + 1 : 0 ;
print lineOut $theNext if $ready -- > 0 && $$theNext[0] > $firstEnd ;
}
# 3. æ®ã£ã¦ãããã®ãæ¸ãåºã
print lineOut $_ for grep { $$_[0] > $o{e} } @stockLines ;
# 4. æ¨æºã¨ã©ã¼åºåã«äºæ¬¡æ
å ±ãæ¸ãåºãã
my $n = $. =~ s/(?<=\d)(?=(\d\d\d)+($|\D))/,/gr ;
my $msg = "-- $n lines are read and $oc lines are output. To suppress this message on STDERR, run as `$Script -20'. " ;
say STDERR FAINT BOLD $msg if 0 ne ($o{2}//'') ;
}
sub fitCheck ( $ ) { # è¡çªå·ã弿°ã«ä¸ãããããã¨ããããåºåå¯è½ã«è©²å½ããããå¤å®ããã@numsãæé»ã«æä½ãã¦ããã
my $head = shift @nums ; # æ°ç ãåããããªã¤ã¡ã¼ã¸ã§å¦çããã
while ( $head < $_[0] ) { push @nums , $head * $o{b} ; $head = shift @nums }
if ( $head < $_[0] + 1 ) { push @nums , $head * $o{b} ; return $_[0] >= $o{f} } #
unshift @nums, $head ;
return $_[0] >= $head - $o{B} && $_[0] <= $head + $o{A} && $_[0] >= $o{f} ;
}
## ãã«ãã®æ±ã
sub VERSION_MESSAGE {}
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 [-z] [-B 0] [-A 0] [-p 1] [-f 1] [-e 2]
大ããªããã¹ããã¡ã¤ã«ã®å
¨ä½ãææ¡ããããããããã
( run in 1.185 second using v1.01-cache-2.11-cpan-d8267643d1d )