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

What is going on here?
use Data::Dump::Streamer; print Dump({1,2}),"\n\n"; print Dump({1,2})."\n\n"; __END__ $HASH1 = { 1 => 2 }; Data::Dump::Streamer=HASH(0x1ed0914)

Replies are listed 'Best First'.
Re: Data::Dump::Streamer Dump in concatenation
by Anonymous Monk on Jul 18, 2009 at 12:25 UTC
    This seems to work
    BEGIN{ use Data::Dump::Streamer(); package Data::Dump::Streamer; use overload '""' => sub { return $_[0]->Out }; } use Data::Dump::Streamer; print Dump({1,2}),"\n\n"; print Dump({1,2})."\n\n"; __END__
    adding use overload '""' => sub { return $_[0]->Out }; to Data-Dump-Streamer-2.09/lib/Data/Dump/Streamer.pm breaks these tests
    t/as.t t/dump.t t/usage.t
Re: Data::Dump::Streamer Dump in concatenation
by ikegami (Patriarch) on Jul 18, 2009 at 07:24 UTC
    You're completely misusing the function. Dump does not return a string to print. The proper usage is:
    Dump({1,2}); print "\n\n";
      Are you sure? It says in docs
      my $obj=Dump($x,$y); # Returns an object my $str=Dump($x,$y)->Out(); # Returns a string of the dump. my @code=Dump($x,$y); # Returns a list of the dump. Dump($x,$y); # prints the dump. print Dump($x,$y); # prints the dump.
        Ah, so it does. Probably because the author figured many people would try to use it that way anyway. I missed it originally because the first and only appearance of this usage is halfway through the substantial documentation. The docs are very clear that it only works in list context, though. (Anything else would conflict with the normal usages.)