我想过滤自己的输出而不为此编写单独的程序。有可以调整的 perl5 解决方案。有没有像新语言支持的更好的东西?
head(100);
while (<>) {
print;
}
sub head {
my $lines = shift || 20;
return if $pid = open(STDOUT, "|-");
die "cannot fork: $!" unless defined $pid;
while (<STDIN>) {
print;
last unless --$lines ;
}
exit;
}