http://qs321.pair.com?node_id=994842

Freezer has asked for the wisdom of the Perl Monks concerning the following question:



Dear Monks,

What is the best way to to combine variables to create one virtual variable? For example with the following piece of code I don't want to have to repeat this statement 4 times because the amout of Perl code generated becomes difficult to manage. If possible I want the code to make it obvious that we are dealing with a fusion of two variable names. So, for example,  $sth_Count_Ref_vs_Comp.$letter_tag Then I just need to change the letter tag within a loop.
my $sth_Count_Ref_vs_Comp = $dbh_B->prepare($sql_count_A_Ref_vs_ +Comp) or die "Cannot prepare: " . $dbh_B->errstr(); $sth_Count_Ref_vs_Comp->execute() or die "$sth_Count_Ref_vs_Comp +->errstr\n"; my $sth_Count_Ref_vs_Comp_B = $dbh_B->prepare($sql_count_A_Ref_v +s_Comp_B) or die "Cannot prepare: " . $dbh_B->errstr(); $sth_Count_Ref_vs_Comp_B->execute() or die "$sth_Count_Ref_vs_Co +mp_B->errstr\n"; my $sth_Count_Ref_vs_Comp_C = $dbh_B->prepare($sql_count_A_Ref_v +s_Comp_C) or die "Cannot prepare: " . $dbh_B->errstr(); $sth_Count_Ref_vs_Comp_C->execute() or die "$sth_Count_Ref_vs_Co +mp_C->errstr\n"; my $sth_Count_Ref_vs_Comp_D = $dbh_B->prepare($sql_count_A_Ref_v +s_Comp_D) or die "Cannot prepare: " . $dbh_B->errstr(); $sth_Count_Ref_vs_Comp_D->execute() or die "$sth_Count_Ref_vs_Co +mp_D->errstr\n";