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

RE: How to manage large Conditional Statement

Thread Previous | Thread Next
From:
Mimi Cafe
Date:
April 21, 2010 07:55
Subject:
RE: How to manage large Conditional Statement
Message ID:
4bcf11c2.cb19cc0a.09f5.ffffadc8@mx.google.com


>> -----Original Message-----
>> I'm talking for myself here, but the way I usually do this is that I wrap
>> up each SQL query or set of related SQL queries in a subroutine.
>> 
>> If the sub's going to be used as a predicate I make sure it returns
>> true/false and pass all of the relevant data as arguments. By giving it a
>> suitable name, I end up with nicely readable code like
>> 
>> 	[...]
>> 	if( isSomeCondition( $foo, $baz, $bar ) ){
>> 	[...]
>> 
>> More or less straight out of Perl Best Practices, Chapter 3.
>> 
>> HTH,
>> Thomas

I agree with both Thomas and Uri and I will move the SQL/DBI stuff to a sub.

Earlier I thought of using an eval or BEGIN block to evaluate the SQL, but
then I thought wait a minute, that wouldn't be the correct way of using
them. Now I see that doing as you guys recommended is the right way forward.

I fell in love with Perl and open source several years back, but I don't
program much, so each time I sit down to program Perl, I find myself going
back to reference books and this list as I have forgotten pretty much of my
Perl knowledge. In one of my past project I had all the SQL stuff in a
module, but it looks like I didn't plan properly this time.

Uri: I think the quoting is much a religious issue as everyone has their
preferred way, but I now know what you meant. :-)

Thanks
Mimi





Thread Previous | Thread Next


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