Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Traverse an unknown multi-dimensional hash

by Anonymous Monk
on Jul 27, 2012 at 18:05 UTC ( [id://984058]=note: print w/replies, xml ) Need Help??


in reply to Re: Traverse an unknown multi-dimensional hash
in thread Traverse an unknown multi-dimensional hash

how would i do something like 1 => a =>i =>level 3
1=> a=> =>ii => level3
1=>a=>iii=>level3
etc.... Please help
  • Comment on Re^2: Traverse an unknown multi-dimensional hash

Replies are listed 'Best First'.
Re^3: Traverse an unknown multi-dimensional hash
by Anonymous Monk on Jul 27, 2012 at 18:10 UTC
    How would i print the output like this : 1 => a =>i =>level 3 1=> a=> =>ii => level3 1=>a=>iii=>level3 etc I could not workout the code to go back to the start and traverse back.
        traversing is fine. i replyed to the same post i want it to print as 1 => a =>i =>level 3
        1=> a=> =>ii => level3
        1=>a=>iii=>level3
        as after traversing till level 3 in firs line.....how reset the patent to 1->a?
      ub dumpHash { my ($element, $indent) = @_; $indent ||= ''; return " = $indent$element\n" unless 'HASH' eq ref $element; my $str= ''; for my $key (sort keys %$element) { $str .= "$indent$key :"; $str .= dumpHash ($element->{$key}, $indent . ' '); } return $str;
      output :
      toplevel-1 : sublevel1a : = value-1a sublevel1b : = value-1b toplevel-2 : sublevel1c : value-1c.1 : = replace +ment-1c.1 value-1c.2 : = replacement-1c.2 sublevel1d : = value-1d
      but i want
      toplevel-1 : sublevel1a : = value-1a toplevel-1 : sublevel1b : = value-1b
        Yes, I understand by now that you're trying to get rid of newlines, that is great, but where is your modification of dumpHash, with code tags, where you try?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found