develooper Front page | perl.beginners | Postings from April 2010

Re: How to manage large Conditional Statement

Thread Previous
Uri Guttman
April 20, 2010 21:35
Re: How to manage large Conditional Statement
Message ID:
>>>>> "MC" == Mimi Cafe <> writes:

  MC> I need to evaluate a statement in an if, elsif, else block, and
  MC> the statement to evaluate in the elsif is too large as I need to
  MC> run a SQL query and act on the return value.  What would be a
  MC> better way to achieve this? Putting the SQL statement elsewhere
  MC> outside the block cannot be right, so I am wondering what to do
  MC> here.

first off, show some code. you can't improve something without seeing

in general don't put large chunks of code inside conditionals. and with
sql and dbi code, i like to wrap them in subs and call them as
needed. that both keeps the sql/dbi code separated and allows for reuse
of the code. in fact i recently did a project where i put all the dbi
code in a separate module as several scripts were going to share
it. even if each script didn't use all the subs, it makes for better
code organization.


Uri Guttman  ------  -------- --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ---- ---------

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About