use File::Temp; use Carp; # Takes code to be evaled, supresses printing and returns # the text that would have been printed. sub eval_print_trap { my $code = shift; my $temp_fh = tempfile(); my $saved_fh = select($temp_fh); eval($code); select($saved_fh); if ($@) { confess("Evaling \n'$code'\ngave error $@"); } seek($temp_fh, 0, 0); wantarray ? <$temp_fh>: join '', $temp_fh; }