App-Bin4TSV
view release on metacpan or search on metacpan
scripts/expskip view on Meta::CPAN
#! env perl
# expskip
# Producec by Toshiyuki Shimono, Tokyo., 2016-01 ~ 07 , 2018-3
# æåã¯ããã¡ã¤ã«ã®å
é ã¨æå¾ã®3è¡ã®ã¿ãåºãã¦ãããã
# éä¸ãææ°é¢æ°çãªè¡çªå·ãåºãããã«ãã¦ã¿ãã
# ãã¡ã¤ã«å㯠headtail, pickall, expskip ã¨å¤é·ãã¦ããã
use 5.014 ; use warnings ;
use Getopt::Std ; getopts "b:e:f:gtp:qzA:B:E",\my%o ;
use Term::ANSIColor qw[ color :constants ] ; $Term::ANSIColor::AUTORESET = 1 ;
use FindBin qw [ $Script ] ;
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 niceNumber ( $ ) ;
$| = 1 ;
my (@nums0, @nums) ;
$o{b} //= 10 ; # åºæ°ã®æå®
$o{e} //= 2 ; # æåã¨æå¾ã®ããããä½è¡ãåºåããã
$o{f} //= 1 ; # éå§è¡ãæå®ããã
$o{A} //= 0 ; # åè´ããè¡ã®ä½è¡å¾ã¾ã§ããã«ç¶ãã¦åºåããã
$o{B} //= 0 ; # åè´ããè¡ã®ä½è¡åã«ããã®ã¼ã£ã¦ç¶ãã¦åºåããã
& Init ;
& traverse ;
exit 0 ;
# (åºåãã)æ¸å¼ã®æå®
sub Init ( ) {
sub lineOutSub ( $ ) ; # lineOutã®ãããªé¢æ°åããã¤ãã®ãã¡ãã©ããã使ãããã
sub lineOutColon ( $ ) { $_[0]->[0], ":\t", $_[0]->[1] } # è¡çªå·ã«ã³ãã³(:) ãä»å ãã¦åºå
sub lineOutG ( $ ) { GREEN $_[0]->[0] , RESET "\t", $_[0]->[1] }
sub lineOutQ ( $ ) { $_[0]->[1] }
sub lineOutTime ( $ ) { sprintf("%02d:%02d:%02d\t", @{[localtime]}[2,1,0]), lineOutSub $_[0] }
* lineOutSub = $o{g} ? * lineOutG : $o{q} ? * lineOutQ : * lineOutColon ;
* lineOut = $o{t}? *lineOutTime : * lineOutSub ;
select * STDERR if $o{E} ; #<-- BOLD DARKã STDERRã®å¾ã«è¿½å ããã¨ã©ããªãã?
@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]) ;
my @t = @{$t{$o{p}//1}} ;
grep {$_ < $o{b} || $_ == 'Inf'} @t
} ;
}
sub traverse ( ) {
my $fnFlag = @ARGV > 1 ;
while ( 1 ) {
my $fn = shift @ARGV ; # ãã¡ã¤ã«å
my $fh ; # ãã¡ã¤ã«ãã³ãã«
if ( defined $fn ) {
open $fh , "<" , $fn or warn "File `$fn' does not open." and next ;
} else {
$fh = *STDIN ;
}
binmode $fh , ":gzip(autopop)" if $o{z} ;
say $fn if $fnFlag ;
eachFile $fh ;
close $fh ;
last if ! @ARGV ;
print "\n" ; # ãã¡ã¤ã«éã®ç©ºè¡
}
}
sub eachFile ( $ ) {
#$. = 0 ;
@nums = @nums0 ;
my $fh = $_[0] ;
my $rd ; # ãã®æ°ãæ£ãªãåºåãããããªã®è¯ãæ°ãªã©ã®ããªã¬ã¼ã§ä¸å®å¤ãæ ¼ç´ããã¦ã1ãã¤æ¸ãä»çµã¿ã
my @stockLines ; # ããã¤ãã®è¡ã®ãæååãæ ¼ç´ããã
* flag_E = $o{E} ? sub { print STDOUT $_ } :sub {} ; # -E ã®æã¯STDERRã«åºãã¤ã¤ãããã®ã¾ã¾teeã®ããã«åºã
# æåã®æ¹ã¯ãã¾ãä¸å®éèªãã
if ( $o{e} > 0 ) {
while ( <$fh> ) {
& flag_E ;
push @stockLines , [ $. , $_ ] ;
last if $. >= $o{e} ;
}
}
print lineOut $_ for @stockLines ;
# æ¡ä»¶ã«ä¸è´ãããã®ã®ã¿åºåããã
while ( <$fh> ) {
& flag_E ;
push @stockLines , [ $. , $_ ] ; # pushã¨shiftã対ã«ãã¦FIFOã®ãããªä»çµã¿
my $lf = shift @stockLines ;
$rd = $o{A}+1 if niceNumber $lf->[0] ;
print lineOut $lf if $rd -- > 0 && $lf->[0] > $o{e} ;
}
print lineOut $_ for grep { $_->[0] > $o{e} } @stockLines ; # æå¾ã«æ®ã£ã¦ãããã®ãæ¸ãåºã
}
# 颿°
sub niceNumber ( $ ) {
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} } # $_[0]ãfloor $head ã«ä¸è´
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
( run in 0.636 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )