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

Re: How to manage large Conditional Statement

Thread Previous
From:
Uri Guttman
Date:
April 20, 2010 21:35
Subject:
Re: How to manage large Conditional Statement
Message ID:
87wrw1xw2v.fsf@quad.sysarch.com
>>>>> "MC" == Mimi Cafe <mimicafe@googlemail.com> 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
it.

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

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About