Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my %hash = ( 'I' => 1, 'II' => { 'A' => 3, 'B' => { '1' => 4, '2' => 5, '3' => 6} }, 'III' => 2 ); print_hash(\%hash); sub print_hash { my($href) = @_; foreach my $key (keys %$href) { if (ref($$href{$key}) eq 'HASH') { my $href2 = $$href{$key}; print_hash($href2); } else { print "$key => $$href{$key}\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing Hashes (Without Data Dumper)
by Jenda (Abbot) on May 26, 2003 at 12:21 UTC | |
|
Re: Printing Hashes (Without Data Dumper)
by Skeeve (Parson) on May 26, 2003 at 12:27 UTC | |
|
Re: Printing Hashes (Without Data Dumper)
by arthas (Hermit) on May 26, 2003 at 12:18 UTC | |
|
Re: Printing Hashes (Without Data Dumper)
by broquaint (Abbot) on May 26, 2003 at 13:34 UTC | |
|
Re: Printing Hashes (Without Data Dumper)
by Abigail-II (Bishop) on May 26, 2003 at 12:53 UTC | |
|
Re: Printing Hashes (Without Data Dumper)
by BrowserUk (Patriarch) on May 26, 2003 at 14:19 UTC | |
|
Re: Printing Hashes (Without Data Dumper)
by Anonymous Monk on May 26, 2003 at 16:52 UTC |