Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Devel::Peek Dump() not printing out

by ultranerds (Hermit)
on Feb 20, 2017 at 16:56 UTC ( [id://1182356]=perlquestion: print w/replies, xml ) Need Help??

ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm try to write a script that accesses a "curl" command to grab a paypal transaction back. The "grab" works ok, but I'm having fun with the utf8 characters. I'm trying to do some debugging using Devel::Peek, but it doesn't want to work. I literally get no output. I know the command is running, as I'm putting debug text either side of the code, and they print fine. Surely this is right?
use Devel::Peek; Dump("foo");
I've even tried:
use Devel::Peek; Devel::Peek::Dump("foo");
and
use Devel::Peek; print Dump("foo");


What am I doing wrong? I'm baffled

Thanks

Andy

Replies are listed 'Best First'.
Re: Devel::Peek Dump() not printing out
by haukex (Archbishop) on Feb 20, 2017 at 17:02 UTC

    Hi ultranerds,

    Works for me. Can you post an SSCCE that reproduces the problem on your end? Note that Devel::Peek prints to STDERR, are you sure you're not redirecting that to somewhere else?

    $ perl -wMstrict -MDevel::Peek -e 'Dump("foo");' SV = PV(0x21783a0) at 0x20a31e0 REFCNT = 1 FLAGS = (POK,IsCOW,READONLY,PROTECT,pPOK) PV = 0x20b7f20 "foo"\0 CUR = 3 LEN = 10 COW_REFCNT = 0

    Regards,
    -- Hauke D

      Thanks for the reply. There must be something funky going on :/ This simple test script:
      #!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); print "Content-Type: text/html\n\n";# print "BLA"; use Devel::Peek; Dump("foo"); print "HERE\n";
      From the browser, I get:
      BLAHERE 
      Yet it work fine from SSH:
      perl test.cgi Content-Type: text/html SV = PV(0x2518cd0) at 0x2535bc0 REFCNT = 1 FLAGS = (POK,READONLY,IsCOW,pPOK) PV = 0x268bb90 "foo"\0 CUR = 3 LEN = 10 COW_REFCNT = 0 BLAHERE
      Any ideas?

      Thanks!

        Hi ultranerds,

        As I said, the output is to STDERR, which won't be sent to the browser, it'll most likely end up in your server log instead. As far as I can tell, Devel::Peek does not offer an option to change where its output goes, even its tests have to jump through some hoops to get its output. The following is the best I can come up with off the top of my head, perhaps another monk knows a better method.

        $ perl -wMstrict 2>/dev/null use Devel::Peek; use Capture::Tiny qw/capture_stderr/; my $dump = capture_stderr { Dump "foo" }; print $dump;

        Hope this helps,
        -- Hauke D

Re: Devel::Peek Dump() not printing out
by ikegami (Patriarch) on Feb 22, 2017 at 20:42 UTC

    Keep in mind that `Dump` writes to STDERR, not STDOUT.

    Furthermore, it might not be affected by attempts to redirect STDERR from within Perl.

    (The third snippet you posted is wrong.)

      This has already been pointed out ikegami

        Great!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1182356]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2024-04-25 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found