<?xml version="1.0" encoding="windows-1252"?>
<node id="553004" title="Re^3: Help with Hash of hashes, is there a better way?" created="2006-06-01 05:24:20" updated="2006-06-01 01:24:20">
<type id="11">
note</type>
<author id="381608">
ikegami</author>
<data>
<field name="doctext">
&lt;p&gt;&lt;b&gt;Option 2)&lt;/b&gt;

&lt;p&gt;A callback would be simpler:

&lt;c&gt;
{
   iterate {
      my (
         $env_name,
         $platform_name,
         $host_name,
         $target_name,
         $total_capacity,
         $free_capacity,
      ) = @_;
   
      local $, = "\t";
      local $\ = "\n";

      print $env_name,
            $platform_name,
            $host_name,
            $target_name,
            $total_capacity,
            $free_capacity;
   } $stuff;
}
&lt;/c&gt;

&lt;readmore title="sub iterate"&gt;
&lt;c&gt;
sub iterate(&amp;$) {
   my ($callback, $envs) = @_;
                      
   while (my ($env_name,      $platforms) = each %{$envs     }) {
   while (my ($platform_name, $hosts    ) = each %{$platforms}) {
   while (my ($host_name,     $targets  ) = each %{$hosts    }) {
   while (my ($target_name,   $target   ) = each %{$targets  }) {
      my $total_capacity = $target-&gt;{total_capacity};
      my $free_capacity  = $target-&gt;{free_capacity};
      
      $callback-&gt;(
         $env_name,
         $platform_name,
         $host_name,
         $target_name,
         $total_capacity,
         $free_capacity,
      );
   }}}}             
}
&lt;/c&gt;
&lt;/readmore&gt;

&lt;p&gt;Tested.

&lt;!--
&lt;p&gt;Note: I used a different naming convention than yours in my posts to help me develop the code.

&lt;ul&gt;
&lt;li&gt;Variables with singular names (such as &lt;c&gt;$platform&lt;/c&gt;) contain a referance to an "object" of that type.
&lt;li&gt;The name of that object (e.g. "unix") is contained in a variable with the "_name" suffix (e.g. &lt;c&gt;$platform_name&lt;/c&gt;).
&lt;li&gt;Variables with plural names refer to lists of objects of that type. (e.g. &lt;c&gt;$platforms&lt;/c&gt; contains a reference to a list of platforms).
&lt;/ul&gt;
--&gt;
</field>
<field name="root_node">
552989</field>
<field name="parent_node">
552994</field>
</data>
</node>
