in reply to Help paring down massive subroutine
Given how nicely you have kept variable names, param names and DB field names consistent, I'd wager that you'll find it fairly easy to reduce quite a bit of that code into a nested loop over these names. Use a hash keyed by field name to store values that should be sent to the DB, rather than using separate scalars named for each field -- e.g.:
You might even find a way to extend the use of that hash so that the field names involved appear only once or twice in the whole subroutine, rather than several times (and likewise for other parameter/field sets). Personally, I always find it a nice feature when I can reduce the number of times that I write a given set of names in a script.$sql_statement = "update timecard set " foreach $fname ( keys %fieldhash ) { $sql_statement .= "$fname = $fieldhash{$fname}," if ( $fieldhash{$ +fname} ); } $sql_statement =~ s/,$/ WHERE /; $sql_statement .= "blah = blah etc...";
|
|---|