SPUG: Slice of HashOfHash

Eric.D.Peterson at alltel.com Eric.D.Peterson at alltel.com
Thu Nov 16 15:56:30 PST 2006


 
Thanks for all your ideas, it has pointed me into the right direction.
Here's essentially what I got working. Still fine-tuning it.  The last
note I saw on this list was about the excessive calls in the foreach
below.  Since I'm not working with a huge amount of data (otherwise) I'd
run out of memory), I'm not to concerned.  Just so I get the proper data
in a timely manner.  And so far it is (I think), I'm still validating
output to input. 

I agree that I need to better name my objects and hash names.  I'll get
there. :)




# ---------- ---------- ----------
# loop through different hash has 
# that has names to look up in big HoH
# ---------- ---------- ----------
for my $name ( sort keys %names )
{
    $name = lc ( trim ( $name ) );
    print "\n\t\t$name \n";
    
        # ---------- ---------- ----------
        # Get a subset of all our data based on the name
        # ---------- ---------- ----------
        %subHoH = (); # start empty
        while ( my ( $key, $obj ) = each %HoH ) 
        {
            $subHoH{$key} = $obj if ( $obj->{'name '} && 
                                      $obj->{'name '} eq $name );
        }
        print Dumper ( \%subHoH ) if DEBUG2;
    
        # ---------- ---------- ----------
        # print out sorted by level and id for only this name
        # ---------- ---------- ----------
         foreach my $me ( sort { $subHoH{$a}->{'level'} <=>
$subHoH{$b}->{'level'} ||
                                 $subHoH{$a}->{'id'}    <=>
$subHoH{$b}->{'id'}
                               } keys %subHoH )
        { 
            if ( $subHoH{$me}->{'level'} == 0 )
            {   
                # ---------- ---------- ----------
                # recursive call, to walk through the subHoH and 
                # print parent information based on this starting ID
                # ---------- ---------- ----------
                &print_parent ( $subHoH{$me}->{'id'} ) if
$subHoH{$me}->{'id'} > 0;
            }
        }
    }
}
%subHoH = ();  # clean up after all done




******************************************************************************************
The information contained in this message, including attachments, may contain 
privileged or confidential information that is intended to be delivered only to the 
person identified above. If you are not the intended recipient, or the person 
responsible for delivering this message to the intended recipient, Alltel requests 
that you immediately notify the sender and asks that you do not read the message or its 
attachments, and that you delete them without copying or sending them to anyone else. 




More information about the spug-list mailing list