in reply to Help required to improve code

First impression, since your hash keys are the same as your column names, you might want to replace

while(@results = $sth -> fetchrow_array) { $index++; $SearchResults[$index]{'id'} = $results[0]; $SearchResults[$index]{'searchterm'} = $results[1]; $SearchResults[$index]{'magazinetitle'} = $results[2]; $SearchResults[$index]{'issueno'} = $results[3]; $SearchResults[$index]{'startpage'} = $results[4]; $SearchResults[$index]{'endpage'} = $results[5]; $SearchResults[$index]{'buynow'} = $results[6]; $SearchResults[$index]{'index'} = $index; $SearchResults{'count'} += 1; }

with

{ my $i = {}; @SearchResults = @{$sth->fetchall_arrayref($i)}; $SearchResults{count} = ++$#SearchResults; }

...just 'cuz I'm guessing DBI's faster than you are. ;-)

Looks like you could hoist a bunch of stuff out of those loops in your subroutines, too. But as I see ".asp" which stands for "Ain't Stuff for Petruchio", I'll leave that to the smarter monks... many of whom will doubtless tell you to use strict, by the way.

Replies are listed 'Best First'.
Oops!
by Petruchio (Vicar) on Oct 05, 2000 at 10:34 UTC
    Dag nab it! Posted anonymously... oh, well... who needs XP anyway? :-)