$VAR1 = [ { 'nodeType' => 'node', 'value' => '1', 'text' => 'int', 'children' => [ { 'nodeType' => 'node', 'value' => '1', 'text' => 'num', 'id' => 'int-num', 'leaf' => 'true' } ], 'id' => 'int', 'leaf' => 'false' }, { 'nodeType' => 'node', 'value' => '10.2.200.21', 'text' => 'device', 'children' => [ { 'nodeType' => 'node', 'value' => 'image1', 'text' => 'ftp_image_name', 'id' => 'device-ftp_image_name', 'leaf' => 'true' }, { 'nodeType' => 'node', 'value' => '6.1', 'text' => 'ftp_image_version', 'id' => 'device-ftp_image_version', 'leaf' => 'true' }, { 'nodeType' => 'node', 'value' => 'build/', 'text' => 'ftp_image_path', 'id' => 'device-ftp_image_path', 'leaf' => 'true' }, { 'nodeType' => 'node', 'value' => '10.2.200.21', 'text' => 'ftp_server', 'id' => 'device-ftp_server', 'leaf' => 'true' } ], 'id' => 'device', 'leaf' => 'false' } #### $VAR1 = { 'int' => { 'num' => {} }, 'device' => { 'ftp_image_path' => {}, 'ftp_image_version' => {}, 'ftp_image_name' => {}, 'ftp_server' => {} } }; #### 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); #2 MY PROBLEM IS HERE I WANT TO SET THE VALUES THAT MATCH THE KEYS BASED ON THE NEWLY BUILD HASH #if($child->{leaf}){ # #} if($child->{children}){ $self->_process_attributes($child->{children},$attributes) } } return $attributes; } 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 necessary. # 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; }