Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to print a multi-level Hashes of Hashes without the use of a module

by BrowserUk (Patriarch)
on Jan 25, 2015 at 02:11 UTC ( [id://1114404]=note: print w/replies, xml ) Need Help??


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

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
  • Comment on Re: How to print a multi-level Hashes of Hashes without the use of a module
  • Download Code

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

    Hello BrowserUk,

    Thank you for your time and effort. I will try to experiment with your solution a little bit to become familiar. I was not aware that you can call the same subroutine inside the actual subroutine.

    Again thank you for your time and effort reading my question and replying.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

        Hello Athanasius,

        Wow thank you for your time and effort providing me all these tutorials. To be honest at the beginning it was not the easiest thing to understand, but reading one after the other tutorial it started to make more sense. Thank you again for your time and effort.

        Seeking for Perl wisdom...on the process of learning...not there...yet!
      I was not aware that you can call the same subroutine inside the actual subroutine.

      You may want to have a look at recursion, which Perl supports.

        Hello Anonymous Monk,

        Thank you for your time and effort to provide me with more information. It starts to make more sense to me know.

        Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found