in reply to How to iterate through a hash of hashes?
This method recursively drops down to the bottom level of any depth of hash of hashes, and prints the end values.
use strict; use warnings; my %hash = ( "192.168.0.1" => { "randy" => "thomas", "ken" => "samual" }, "192.168.0.2" => { "jessie" => "jessica", "terry" => "ryan" } ); traverse( \%hash ); sub traverse { if( ref( $_[0] ) =~ /HASH/ ) { traverse( $_[0]{$_} ) foreach keys %{$_[0]}; } else { print "$_[0]\n"; } }
The limit to levels of depth is 100 for most Perls, unless you turn off the warning for deep recursion with no warnings qw/recursion/; inside the traverse()sub.
Dave
|
|---|