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;