I was able to solve my problem by doing the following. I'm sure there is a much more elegant solution and I would love to see it....but if anyone else is facing something like this hopefully it helps:
#********************************************************************* +************** # protected _process_attributes # ***************************** # Uses: Recursively searches through a tree structure to process/f +ind attributes # Params: HASH with device and interface attributes # Return: The updated command and result set after template process +ing #********************************************************************* +************** sub _process_attributes{ my $self = shift; my $child_tree = shift; my $attributes = shift || {}; my $attribute_values; foreach my $child (@$child_tree){ my $attribute_key = $child->{id}; my @attribute_array = split('-',$attribute_key); my $key; my $current_key; my $next_key; $attributes = hash_maker($attributes,@attribute_array); if($child->{children}){ $self->_process_attributes($child->{children},$attributes) } if($child->{leaf}){ nested_keys($attributes,\@attribute_array,$child->{value}) +; } } return $attributes; } sub nested_keys{ my $attributes = shift; my $attribute_array = shift; my $value = shift; foreach my $attr (@$attribute_array){ foreach my $k (keys %$attributes){ unless($k eq $attr){ next; } my $num_keys = keys %{$attributes->{$k}}; if(ref($attributes->{$k}) eq 'HASH' && $num_keys > 0){ shift(@$attribute_array); nested_keys($attributes->{$k},\@$attribute_array,$valu +e); } else { $attributes->{$k} = $value; return; } } } } sub hash_maker { my $ref = shift; my $key = shift; return undef unless ref $ref eq 'HASH'; # # If $key is empty, we're building an empty hash. Return undef. # return undef unless $key; # # This is the passed in hash, so we need to duplicate it in our new # data structure. We also have to be sure that we're adding if neces +sary. # if ( ref $key eq 'HASH' ) { my $hash; my $count = keys %$key; my $cnt = 1; foreach my $k ( keys %{$key} ) { $ref->{$k} = $key->{$k}; } return $ref; } # # Reference was not a hashref, we don't know how to handle it. # return undef if ref $key; # # Nothing above was met, there's more to build. # $ref->{$key} = {} unless exists $ref->{$key}; #shift(@_); hash_maker( $ref->{$key}, @_ ); # # Pass that which we hath groweth to those who groweth before us... # return $ref; }

In reply to Re: Setting nested hash values recursively by josh803316
in thread Setting nested hash values recursively by josh803316

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.