I want to filter own output without writing separate program for that. There is perl5 solution that may be adapted. Is there something better that can be done like that new language supports?
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;
}