Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 21st, 2006, 10:53 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default optimise it or speed up execution time perl script

i have the top while loop in my code, then three more of the foreach loop. is there any way to optimise it or speed up execution time? thanks.
Code:
# get a list of the current tables on tiger
open(IN, "/usr/local/piccosearch/crmpicco_rangers");
while(<IN>) {
    chomp;
    (undef, $table) = split(/:/);
    if ($table =~ /^package/) {
        push(@tables, $table);
    }
}
close(IN);

# loop through all the tables
foreach $table (@tables) {
    @thecursor = $sql->execSql("SELECT DISTINCT(stadium),city,country FROM football.$table", 1);
    while ($result = $thecursor[0]->fetchrow_hashref) {
        if ($result->{"stadium"} ne "") {
            $stadium = $result->{"stadium"};
            $city = $result->{"city"};
            $country = $result->{"country"};            

            if ($stadium eq "") {
                $filestr .= "park: $stadium - cty: $city - ctry: $country\n";
            }
        }
    }
}
www.crmpicco.co.uk
www.ie7.com
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
  #2 (permalink)  
Old November 22nd, 2006, 07:55 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Well, the obvious thing would be to have all your stadiums (stadia?) in the same table in your database. That'd get rid of the need to store them in a text file and let you get rid of your foreach loop. I guess your table would be something like:

<code>
SELECT DISTINCT (stadium), city, country
           FROM stadiums;

|id |stadium |city |country |
---------------------------------------
|1 |wembley |london |uk |
...etc.
</code>

You could also drop the embedded if statement, because it will always be false - the stadium field can't be both blank and non-blank at the same time i.e.

<code>
if ($result->{"stadium"} ne "") { # if stadium field IS NOT blank...
  # ...
  $stadium = $result->{"stadium"};
  # ...
  if ($stadium eq "") { # ...and if stadium field IS blank
  # ...
}
</code>

HTH
Charlie

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
  #3 (permalink)  
Old November 22nd, 2006, 08:31 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks again Charlie

www.crmpicco.co.uk
www.ie7.com


Similar Threads
Thread Thread Starter Forum Replies Last Post
speed up slow Perl code with SQL statements crmpicco Perl 3 May 11th, 2007 05:21 AM
connecting to XML document with Perl script crmpicco XML 0 October 18th, 2006 12:00 PM
Script execution... dzagore2 Classic ASP Professional 0 May 9th, 2006 03:42 AM
script execution prob.. dzagore2 Classic ASP Basics 0 May 8th, 2006 04:18 AM
script execution time madhukp Classic ASP Basics 2 February 2nd, 2005 04:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.