Data::Dumper would work - but if you actually want to do something special with the data, sort it in a special way, or change the output style you might want to define your own function to dump things recursively. If you wanted to do this on the web you could replace "\n" with <br> and "\t" with <dd> or wrap some <ul >.. </ul >around each recursive call.
#!/usr/bin/perl -w
use strict;
my %test;
$test{'bio'}{900}{1} = 40;
$test{'bio'}{900}{2} = 45;
$test{'bio'}{901}{1} = 38;
$test{'chem'}{1800}{1} = 27;
$test{'chem'}{1800}{3} = 47;
print_recursive(\%test);
sub print_recursive {
my ($hash,$depth) = @_;
return unless $hash && ref($hash) =~ /HASH/i;
$depth ||= 0;
foreach my $key ( keys %{ $hash } ) {
print "\t"x$depth, $key, "\n";
print_recursive($hash->{$key},$depth+1);
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.