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

As repellent has pointed out, the way to get Devel::Peek::Dump to write to a string is to redirect STDERR to a string. However, if you are running on certain *nixes (Debian-Etch/Perl 5.8.8 and possibly others), the first time you call Devel::Peek::Dump whilst STDERR is redirected to a string, you may see a "Use of uninitialized value in subroutine" warning. This warning does not seem to appear on Windows (so saith ikegami who tried it on Windows for me).

As near as we could tell, this a bug in Devel::Peek::Dump. It has been reported and ticketed as bug 63498. The bug is rated low severity, so you may have to wait a while before this particular annoyance goes away.

Best, beth

Update: more clearly identified systems with potential problems

Replies are listed 'Best First'.
Re^2: Devel::Peek output to a string?
by repellent (Priest) on Feb 26, 2009 at 00:34 UTC
    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";
      Apparently so! I thought I made sure of that.
      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

Re^2: Devel::Peek output to a string?
by repellent (Priest) on Feb 25, 2009 at 22:45 UTC
    Hmmm... I don't see the bug on my Linux box:
    $ cat /etc/redhat-release Red Hat Enterprise Linux WS release 4 (Nahant Update 4) $ perl -v This is perl, v5.8.5 built for i686-linux-thread-multi Copyright 1987-2004, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge.

    UPDATE: I was wrong. My use warnings; was commented out. Bug confirmed on my platform.