http://www.perlmonks.org?node_id=433638


in reply to Re: In need of a Dumper that has no pretentions to being anything else.
in thread In need of a Dumper that has no pretentions to being anything else.

Thankyou Aristotle.

In it's veryCompact form the output is exactly what I was looking for:

P:\test>perl -MDumpvalue -e" $d=new Dumpvalue; $h{ $_ } = [ map{ $_ & 1 ? { 'a'..'z' } : [ 1..100 ] } 1 .. 10 ] for 'a' .. 'j'; $d->veryCompact(1); $d->dumpValue( \%h )" 'a' => ARRAY(0x1871700) 0 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 1 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 3 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 4 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 5 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 6 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 7 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 8 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 9 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 'b' => ARRAY(0x18757e4) 0 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 1 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 3 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 4 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 5 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 6 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 7 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 8 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 9 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 'c' => ARRAY(0x18794fc) 0 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 1 0..99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

And it even has an option to see through overloading and handle what comes out -- at least part way.

P:\test>p1 perl> use Math::Pari qw[ :int factorint sqrtint divisors PARI ];; perl> $f = factorint 1000000;; perl> use Dumpvalue;; perl> $d = new Dumpvalue;; perl> $d->veryCompact( 1 );; perl> $d->set( bareStringify => 1 );; perl> { local $\; $d->dumpValue( $f ) };; 0 Math::Pari=ARRAY(0x1a3702c) 0 Math::Pari=SCALAR(0x1a3c9ec) -> 33884400 1 Math::Pari=SCALAR(0x1a3ec7c) -> 33884376 1 Math::Pari=ARRAY(0x1a36f54) 0 Math::Pari=SCALAR(0x1a3ec70) -> 33884388 1 Math::Pari=SCALAR(0x1a3ec94) -> 33884364 perl> Terminating on signal SIGINT(2)

All it needs is to not de-overload the final SCALAR values so that Math::Pari will return the numbers, which as it's in Perl, I can fix.

It also does circularity testing:

perl> $r = \$r;; perl> $d->dumpValue( $r );; -> REF(0x22ac9c) -> REUSED_ADDRESS

But dumping my testcase above, it uses less than 50% extra memory--a considerable saving over the 250% of Data::Dumper. Though I now realise that a large proportion of the extra memory is DD consumes is used by building the output in memory rather than dumping straight the select'd output handle.

I think I can see how to reduce that further still--though it may slow it down a little.

And it's been sat there on my machine the whole time! It's a bit embarrassing that I've never noticed it, but I don't ever recall it being mentioned.

Not only did someone else see the need for what I was asking for, they wrote it, covered all the bases and dropped it on my machine without telling me:)

Once again, thanks Aristotle.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.