# Takes a filehandle and filename and has output to that handle go # to STDERR and to that filename. It will work even if the handle # being tied is STDERR itself. No escaping is done for the filename, # caveat programmer sub tee_to_stderr { my $file = shift || die "No filename passed\n"; my $ip = open (STDERR, "| perl") || die "Cannot pipe to Perl: $!"; my $fh = select(STDERR); $| = 1; select($fh); print STDERR qq( unless(open (OUT, ">$file")) { print STDERR "Cannot write to $file: \$!\n"; kill 9, getppid(); } select(STDERR); \$| = 1; select(OUT); \$| = 1; while (<>) { print OUT; print STDERR; } ); print STDERR "\n__END__\n"; } #### open(NEW, ">&OLD") or die "Cannot dup OLD: $!";