in reply to Filling value of nested hash

First, keep in mind that since this is a hash, order is arbtrary so there is no "first" file name. If order matters, you should be using an array of arrays rather than a hash of hashes.

Since you are dealing with an object of unknown depth, a recursive parser is likely easiest. Maybe something like

#!/usr/bin/perl use strict; use warnings; my $VAR1 = { 'File_Handler' => { 'Compile_File' => undef, 'Log_Details' => undef, 'Complete_Logging' => undef, 'Get_Config' => undef, 'Get_Data' => undef, 'Get_Abc_Data' => undef, 'Internal_Operations' => { 'Get_Abc_Data' => + undef, 'Start_Operations +' => undef, 'Get_Start_Up_Dat +a' => undef, 'Construct_Failur +e_Ident' => undef, 'Construct_Additi +onal_Words' => undef, }, 'Start_File_Handler' => undef } }; sub output_files { my $path = shift; my %hash = @_; for my $key (keys %hash) { if (ref $hash{$key}) { output_files("$path.$key",%{$hash{$key}}); } else { print "$path.$key.2.ada\n" } } } while (my($key, $value) = each %$VAR1) { output_files($key, %$value); }

Replies are listed 'Best First'.
Re^2: Filling value of nested hash
by Util (Priest) on Dec 09, 2010 at 17:13 UTC
    You can factor out the recursion with Data::Walker or Data::Leaf::Walker :
    use strict; use warnings; use Data::Leaf::Walker; my %data = ( File_Handler => { Compile_File => undef, Log_Details => undef, Complete_Logging => undef, Get_Config => undef, Get_Data => undef, Get_Abc_Data => undef, Start_File_Handler => undef, Internal_Operations => { Get_Abc_Data => undef, Start_Operations => undef, Get_Start_Up_Data => undef, Construct_Failure_Ident => undef, Construct_Additional_Words => undef, }, }, ); my $walker = Data::Leaf::Walker->new( \%data ); while ( my ( $k, $v ) = $walker->each ) { my $filename = join '.', @{$k}, '2.ada'; print $filename, "\n"; }