My program processes two flavors of 'something' and each flavor has its own data structures and procedures for processing them. User invokes the program with either or both of:
-f1 path_to_file_with_flavor_1_data
-f2 path_to_file_with_flavor_2_data
My program is working coded as:
GetOptions ('f1=s' => \$f1_path,
'f2=s' => \$f2_path,
);
if (defined $f1_path) {
subroutine_to_process_flavor_1_data( $f1_path );
}
if (defined $f2_path) {
subroutine_to_process_flavor_2_data( $f2_path );
}
It has a single hash to store the processed data for both flavors:
my %flv_hash = ( flavor_1 => { datahash => { ... },
},
flavor_2 => { datahash => { ... },
},
);
I now want to add each flavor's variable and subroutine names to the hash to make it:
my %flv_hash = ( flavor_1 => { datahash => { ... },
var_name => 'f1_path',
sub_name => 'subroutine_to_process_flavor_1_data',
},
flavor_2 => { datahash => { ... },
var_name => 'f2_path',
sub_name => 'subroutine_to_process_flavor_2_data',
},
);
and change my program to below pseudo-code:
foreach my $flavor ( keys %flv_hash ) {
if (defined <the variable named $flv_hash{flavor}{var_name}>) {
<call the subroutine named $flv_hash{flavor}{sub_name}>
}
}
I have searched all knowledge bases on the subject of storing and retrieving the names of variables and subroutines in a hash but, being a hardware engineer whose software skills are limited to what I learned in Basic Programming 101 that I took some 35 years ago, I couldn't directly copy the examples and get them to work in the context of my program. Another words, if possible I'd appreciate a solution I can just copy and use without having an in-depth knowledge of the Perl paradigms on which they are based. Thank you again.