If you want to separate the compiler's messages (sent to STDERR) from your own STDERR messages, this will help.

The module is used like so:

use Compiler::Errors 'file.out'; # will append use Compiler::Errors '>file.out'; # will overwrite use Compiler::Errors '>>file.out'; # will append use Compiler::Errors '| program'; # will pipe use Compiler::Errors '>&=1'; # dup to fd
or on the commandline: perl -MCompiler::Errors=file.out -w program
package Compiler::Errors; sub import { shift; # caller my $file = @_ ? shift : "compiler.err"; # default to appending to the file $file = ">> $file" if $file !~ /^[>|]/; open __SAVEERR, ">&STDERR"; # copy STDERR open STDERR, $file; # redirect STDERR } INIT { open STDERR, ">&__SAVEERR"; # restore STDERR close __SAVEERR; } 1;

Replies are listed 'Best First'.
Re: Compiler Errors
by converter (Priest) on Sep 30, 2001 at 22:09 UTC

    Neat. Now how about an option to ANSI colorize compiler and user output?

    Just a thought. You know how much I enjoy finding new work for you. ;)