in reply to Re: Devel::Peek output to a string?
in thread Devel::Peek output to a string?

Could it be that the string variable just has to be initialized to an empty string?
use strict; use warnings; use Devel::Peek; # initialized here my $sOut = ""; close(STDERR); open(STDERR, ">", \$sOut) or die "Can't redirect STDERR to \\\$sOut"; my $s=1; Devel::Peek::Dump $s; Devel::Peek::Dump $s; print "<<$sOut>>\n";

Replies are listed 'Best First'.
Re^3: Devel::Peek output to a string?
by ikegami (Patriarch) on Feb 26, 2009 at 02:07 UTC
    Apparently so! I thought I made sure of that.
Re^3: Devel::Peek output to a string?
by ELISHEVA (Prior) on Feb 26, 2009 at 07:20 UTC
    Great catch! But here's a wrinkle. Other common uses of STDERR redirected to string, namely print, do not require the string variable to be initialized. For example:
    use strict; use warnings; my $sOut; close(STDERR); open(STDERR, ">", \$sOut) or die "Can't redirect STDERR to \\\$sOut"; print STDERR "Hello World!\n"; print $sOut;

    happily outputs "Hello World" without generating a warning (at least on my system). Somehow, I don't think the Devel::Peek::Dump behavior qualifies as Inconsistent for the sake of convenience :-)

    Best, beth