# page 535 in book Programming Perl#!/usr/bin/env perl use v5.14; tee("/tmp/foo", "/tmp/bar", "/tmp/glarch"); while (<>) { print "$ARGV at line $. => $_"; } close(STDOUT) || die "can't close STDOUT: $!"; sub tee { my @output = @_; my @handles = (); for my $path (@output) { my $fh; # open will fill this in unless (open ($fh, ">", $path)) { warn "cannot write to $path: $!"; next; } push @handles, $fh; } # reopen STDOUT in parent and return return if my $pid = open(STDOUT, "|–"); print "\$pid is : $pid"; die "cannot fork: $!" unless defined $pid; # process STDIN in child while (<STDIN>) { for my $fh (@handles) { print $fh $_ || die "tee output failed: $!"; } } for my $fh (@handles) { close($fh) || die "tee closing failed: $!"; } exit; # don't let the child return to main! }
when I run this in ubuntu shell but there is an error:
cannot fork: no such file or directory at ./tf6.pl line 27.
why? somebody give some advice.thanks.
In reply to example in book of Programming Perl does not work. by yangy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |