Perl-Sensitive Sunglasses | |
PerlMonks |
Re: abstraction -- level up!by sacked (Hermit) |
on Jun 16, 2004 at 18:24 UTC ( [id://367362]=note: print w/replies, xml ) | Need Help?? |
If you are able to remove the code that is specific to each selection (i.e., the comparison used to assign a SELECTED element to your result set), than your database code can be generalized (like the code provided by dragonchild above). It appears that you are using CGI::Application. I assume from your code that your template has something like the following for the <TMPL_LOOP> inside a <select> list: If so, the following suggestion may help. You can simplify using HTML::FillInForm. First, remove the logic from your template:
Next, update your database selection code (remove the loop that assigns a SELECTED element):
Next, let HTML::FillInForm handle the selection for you:
This assumes that the selection (in this case, city_id) is passed in as a form parameter. If not, you can assign it yourself:
Now _getBuilderList can be simplified to use a general prepare/select routine:
--sacked
In Section
Seekers of Perl Wisdom
|
|