in reply to How to print a multi-level Hashes of Hashes and extract parts of it
#! perl -slw use strict; use Data::Dump qw[ pp ]; sub dumpIt { my $r = shift; my $d = shift() // 1; die "'$r' not a hashref" unless ref $r eq 'HASH'; print "{" if $d == 1; for( keys %$r ) { if( ref $r->{ $_ } ) { print chr(9) x $d, "$_ => {"; dumpIt( $r->{ $_ }, $d + 1 ); print chr(9) x $d, "}"; } else { print chr(9) x $d, "$_ => $r->{ $_ }"; } } print "}" if $d == 1; } my %multiLevelHash = ( 'firstSampleKey' => 'SampleValue', 'secondSampleKey' => { 'secondLevelSampleKey' => { 'thirdLevelSampleKeyOne' => 'thirdLevelSampleValue', 'thirdLevelSampleKeyTwo' => 'thirdLevelSampleValue', 'thirdLevelSampleKeyThree' => { 'fourthLevelSampleKey' => 'fourthLevelSampleValue', } } } ); dumpIt( \%multiLevelHash ); __END__ C:\test>junk90 { firstSampleKey => SampleValue secondSampleKey => { secondLevelSampleKey => { thirdLevelSampleKeyTwo => thirdLevelSampleValu +e thirdLevelSampleKeyThree => { fourthLevelSampleKey => fourthLevelSam +pleValue } thirdLevelSampleKeyOne => thirdLevelSampleValu +e } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to print a multi-level Hashes of Hashes without the use of a module
by thanos1983 (Parson) on Jan 25, 2015 at 02:50 UTC | |
by Athanasius (Archbishop) on Jan 25, 2015 at 04:07 UTC | |
by thanos1983 (Parson) on Jan 25, 2015 at 13:27 UTC | |
by Anonymous Monk on Jan 25, 2015 at 03:41 UTC | |
by thanos1983 (Parson) on Jan 25, 2015 at 13:25 UTC |