in reply to Saving Standard Output (overloading print())

Well, if it's just for debugging purposes, maybe the direct solution is just to duplicate the print sentence:

use strict; use warnings; my $debug_flag = 0; # not debugging by default $debug_flag = $ARGV[0] if @ARGV == 1; $debug_flag = ( $debug_flag eq lc ( '-debug' ) )? 1 : 0; if ( $debug_flag ) { open DEBUG_FILE, ">debug.out" or die "Cannot open debug file for writing: $!"; } my $output; # do stuff to get the output $output = 'This is a test' . "\n"; print $output; print DEBUG_FILE $output if $debug_flag; # etc...

Not very elegant, true, but print is still the most widely used debugging method, so let's use it...

Another possible, easy way, (if you don't mind losing your stdout output in debug mode) would be to define something like:

# warning, not tested my $out_fh; if ( $debug_flag ) { open FILE, ">debug.out" or die $!; $out_fh = *FILE; } else { $out_fh = *STDOUT; } # and then always do: print $out_fh $output; # it will go to the right place.

The othe solutions are more elegant, but then debugging is always dirty, so...

Good luck,

our $Perl6 is Fantastic;