cat_max
来自「EM算法的改进」· 代码 · 共 86 行
TXT
86 行
#!/usr/bin/perl## $Id: cat_max.txt 1339 2006-09-21 19:46:28Z tbailey $# $Log$# Revision 1.1 2005/07/28 23:51:55 nadya# Initial revision### AUTHOR: Timothy L. Bailey# CREATE DATE:$PGM = $0; # name of program$PGM =~ s#.*/##; # remove part up to last slash@args = @ARGV; # arguments to program$| = 1; # flush after all prints$SIG{'INT'} = 'cleanup'; # interrupt handler# Note: so that interrupts work, always use for system calls:# if ($status = system($command)) {&cleanup($status)}# requirespush(@INC, split(":", $ENV{'PATH'})); # look in entire path# defaults$bufsize = 65536;$usage = <<USAGE; # usage message USAGE: $PGM <max> Reads standard input. Writes standard output. Copies standard input to standard output and quits with $status 1 if more than <max> bytes are written. Copyright (2000) The Regents of the University of California. All Rights Reserved. Author: Timothy L. BaileyUSAGE$nargs = 1; # number of required argsif ($#ARGV+1 < $nargs) { &print_usage("$usage", 1); }# get input argumentswhile ($#ARGV >= 0) { $_ = shift; if ($_ eq "-h") { # help &print_usage("$usage", 0); } else { $max = $_; }}$tot = 0;while ($n = read(STDIN, $_, $bufsize)) { $tot += $n; exit(1) if ($tot > $max); print STDOUT;}exit(0);################################################################################# Subroutines ################################################################################# ################################################################################## print_usage## Print the usage message and exit.#################################################################################sub print_usage { my($usage, $status) = @_; if (-c STDOUT) { # standard output is a terminal open(C, "| more"); print C $usage; close C; } else { # standard output not a terminal print STDERR $usage; } exit $status;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?