Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here is a little dumper I wrote some time ago:
my %h2 = ( 'AAA' => 'aaa', 'BBB' => 'bbb', 'CCC' => { 'A1' => 'a1', 'B1' => 'b1', 'C1' => { 'A2' => 'a2', 'B2' => 'b2', 'C2' => 'c2END', }, }, 'DDD' => 'ddd', ); sub ddump { my $ref = shift; my $deep = shift||1; for my $k ( sort keys %$ref ) { if ( ref $ref->{$k} ) { print "\t" x $deep."$k =>\n"; ddump( $ref->{$k}, $deep+1 ); } else { print "\t" x ($deep)."$k => $ref->{$k}\n"; } } } ddump( \%h2 );
Then I found a column by merlyn, which gave me the idea of dumping into a CGI table structure. The result:
use CGI qw /:all -nph/; #on Win32 $|++; sub nest { my $it = shift; ref $it ? complex_table($it) : $it } sub complex_table { my $hr = shift; # could test here to ensure that $hr is indeed a hash ref. table( { -border => 2, -bordercolor => 'green', -cellspacing => '0 +', }, map Tr( td( {-valign=>'top'}, $_ ), td( nest( $hr->{$_} ))), s +ort keys %$hr ); } my %h1 = (); # feed your HoH here print start_html, complex_table( \%h1 ), end_html;
which produces a dump like this:
AAA aaa
BBB bbb
CCC
A1 a1
B1 b1
C1
A2 a2
B2 b2
C2 c2END
DDD ddd

In reply to Re: How can I visualize my complex data structure? by Discipulus
in thread How can I visualize my complex data structure? by planetscape

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-18 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found