Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Combining variables to create a single virtual variable

by davido (Cardinal)
on Sep 21, 2012 at 08:18 UTC ( [id://994847]=note: print w/replies, xml ) Need Help??


in reply to Combining variables to create a single virtual variable

Identifier names like $sql_count_A_Ref_vs_Comp_B might be indicative of a deeper design problem. But a solution to the immediate problem presented could be:

foreach my $sql ( $sql_count_A_Ref_vs_Comp, $sql_count_A_Ref_vs_Comp_B, $sql_count_A_ref_vs_Comp_C, $sql_count_A_Ref_vs_Comp_D ) { my $sth = $dbh_B->prepare( $sql ) or die "Cannot prepare: " . $dbh +_B->errstr(); $sth->execute() or die $sth->errstr; }

This lets $sql stand in as an alias for each of those sql_count_A_blah_blah_blah variables. Then you just loop over them, repeating the same process for each.


Dave

Replies are listed 'Best First'.
Re^2: Combining variables to create a single virtual variable
by Freezer (Sexton) on Sep 21, 2012 at 09:15 UTC
    Would it then be possible to incorporate this as well? It might be better if I kept the code all strung out and just tidied up the formating :<
    my @row_A_count_A_Ref_vs_Comp; my @fields_A_count_A_Ref_vs_Comp; my @record_A_count_A_Ref_vs_Comp; print BILATERAL_COMPARISONS_A "$sql_count_A_Ref_vs_Comp"; while(my @row_A_count_A_Ref_vs_Comp = $sth_Count_Ref_vs_Comp->fe +tchrow_array()) { print BILATERAL_COMPARISONS_A "\t\t\t\t"; print BILATERAL_COMPARISONS_A "$entry_no_new_MINUS_ONE\t"; + local $\ = "\n"; local $, = "\t"; print BILATERAL_COMPARISONS_A @row_A_count_A_Ref_vs_Comp; + my @record_A_count_A_Ref_vs_Comp = @row_A_count_A_Ref_vs_Com +p; push(my @fields_A_count_A_Ref_vs_Comp, @record_A_count_A_Ref +_vs_Comp); } $sth_Count_Ref_vs_Comp->finish();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://994847]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-25 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found