Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re-Factoring: Philosophy and Approach

by mpeppler (Vicar)
on Nov 02, 2001 at 23:43 UTC ( [id://122899]=note: print w/replies, xml ) Need Help??


in reply to Re-Factoring: Philosophy and Approach

Just a few thoughts regarding the DBI code...

Try to create logical database requests, wrap those in perl subroutines, and place them in a separate module. This will greatly improve the readability of the main script, and will also improve maintainability.

Avoid "select * ..." SQL statements. Be explicit in what you are querying, even if that makes the code more verbose - it'll again improve maintainability.

One thing that is repeating a lot in the code is prepare/execute/fetch one row. Maybe you could use a utility subroutine that does that, something like:

sub fetch_one_row { my $sql = shift; my $sth = $dbh->prepare($sql); $sth->execute; $sth->fetchrow_hashref; }
Just using that could already simplify the code to a great extent.

Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://122899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found