in reply to How to print Hash with multidimensional keys

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); } }

Replies are listed 'Best First'.
Re: Re: How to print Hash with multidimensional keys
by learn_forever (Acolyte) on Jun 05, 2002 at 05:40 UTC
    Thanks
    This is really useful direction.

    Thanks all