develooper Front page | perl.perl5.porters | Postings from September 2010

Peek.pm and displaying array/hash elements

From:
Dave Mitchell
Date:
September 18, 2010 06:56
Subject:
Peek.pm and displaying array/hash elements
Message ID:
20100918135623.GB3932@iabyn.com
The current behaviour of Peek.pm's Dump function (and by extension the
underlying Perl_do_sv_dump() function in dump.c) is most unsatisfactory
when it comes to displaying arrays and hashes, and the elements thereof.
It conflates the 'nest' arg (how many levels deep of recursion to go) with
a 'how many elements to display' arg. This means that with a nest of 1,
one element is dumped; with a nest of two, two elements are displayed,
each element being dumped with a recursion depth of one; with nest == 6,
six elements are dumped, each being recursively dumped in great detail;
etc.

I propose changing the behaviour to the following:

when dumping an array/hash,

if nest == maxnest
    don't display any elements

if nest == maxnest-1
    display *all* elements, but just a compact one line per element:

	Elt "some_key" HASH = 0x5e637a77 VALUE = 0xa6ddd0
	Elt "otherkey" HASH = 0xe4b53fbc VALUE = 0xa39ed8
	...

if nest < maxnest-1
    display all elements, and dump each value at depth (nest+1):

	Elt "some_key" HASH = 0x5e637a77
	    SV = PVGV(0xa4ecd8) at 0xa6ddd0
	      REFCNT = 1
	      FLAGS = (...)
	      ....
	Elt "otherkey" HASH = 0xe4b53fbc VALUE = 0xa39ed8
	    ....

This would be a change to the documented behaviour of Peek.pm.

-- 
Nothing ventured, nothing lost.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About