Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 21st, 2006, 09:53 AM
Friend of Wrox
Points: 7,425, Level: 36
Points: 7,425, Level: 36 Points: 7,425, Level: 36 Points: 7,425, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,532
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
Reply With Quote
  #2 (permalink)  
Old November 22nd, 2006, 06: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
Reply With Quote
  #3 (permalink)  
Old November 22nd, 2006, 07:31 AM
Friend of Wrox
Points: 7,425, Level: 36
Points: 7,425, Level: 36 Points: 7,425, Level: 36 Points: 7,425, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,532
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03:51 AM



All times are GMT -4. The time now is 06:13 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.