Fires of Heaven Guild Message Board  

Go Back   Fires of Heaven Guild Message Board > General forums > Development
User Name
Password
Or, use your gamerDNA username: (more...)
ForumSpy Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-24-2008, 04:36 PM   #1 (permalink)
Seths
Registered User
 
Seths's Avatar
 
Join Date: Jul 2006
Posts: 357
+3 Internets
PERL question

So I spent a few weeks writing a client / server program in PERL to monitor logged in status, program usage, user usage here at the university I work at. I developed it on my windows machine which then decided to crap out so I figured I'd move it to my gentoo box since it has to run on a linux server anyways.

The server program doesn't make any windows system calls so the code should have worked fine and it was bug free on my windows machine. But after moving it over a lot of things stopped working.

Anyways the current issue is with updating the program stats database. in short what the server does is gather up every program in its monitoring list and determine how many instances are running out on the lab machines then puts the total value as the value for that piece of software in a Hash, or associative array. When it comes time to update the DB it does a foreach loop but the problem is it's not updating the DB.

The loop looks like this:

Code:
foreach $key1(keys(%prog_numbers)) { $update = $ldb->prepare("UPDATE LOW_PRIORITY $ldbtable SET $mtime="$prog_numbers{$key1}" WHERE software="$key1""; $showfail = $update->execute; $update->finish(); }
What bugs me is everything worked just fine on my windows box but on Linux its been a pita. I've tried every way I can to loop it, tried pushing all the keys into a normal array, etc. and it's just not finding them in the DB. I've used PHPMyAdmin and ran the exact same query's and they work fine, the only time the query runs but doesn't do anything is if say I type

WHERE software="Acrobat"

instead of

WHERE software="Acrobat.exe"

which is the name of that field in the software column. I have run out of ideas on how to get around this. Any suggestions? Sorry if I was confusing.
Seths is offline   Reply With Quote
Old 03-24-2008, 05:36 PM   #2 (permalink)
Araex
Fires of Heaven WoW Officer
 
Join Date: Jul 2006
Location: Irvine, CA
Posts: 157
-1 Internets
Quote:
Originally Posted by Seths View Post
So I spent a few weeks writing a client / server program in PERL to monitor logged in status, program usage, user usage here at the university I work at. I developed it on my windows machine which then decided to crap out so I figured I'd move it to my gentoo box since it has to run on a linux server anyways.

The server program doesn't make any windows system calls so the code should have worked fine and it was bug free on my windows machine. But after moving it over a lot of things stopped working.

Anyways the current issue is with updating the program stats database. in short what the server does is gather up every program in its monitoring list and determine how many instances are running out on the lab machines then puts the total value as the value for that piece of software in a Hash, or associative array. When it comes time to update the DB it does a foreach loop but the problem is it's not updating the DB.

The loop looks like this:

Code:
foreach $key1(keys(%prog_numbers)) { $update = $ldb->prepare("UPDATE LOW_PRIORITY $ldbtable SET $mtime="$prog_numbers{$key1}" WHERE software="$key1""; $showfail = $update->execute; $update->finish(); }
What bugs me is everything worked just fine on my windows box but on Linux its been a pita. I've tried every way I can to loop it, tried pushing all the keys into a normal array, etc. and it's just not finding them in the DB. I've used PHPMyAdmin and ran the exact same query's and they work fine, the only time the query runs but doesn't do anything is if say I type

WHERE software="Acrobat"

instead of

WHERE software="Acrobat.exe"

which is the name of that field in the software column. I have run out of ideas on how to get around this. Any suggestions? Sorry if I was confusing.
It looks like you're having ambiguous usage of double quotations. In the prepare statement, try changing all the quoations, except the two outmost quotes, to single quotes.

Edit: you're also missing an end-parentheses in the prepare line.

Edit2: Ah, in the editing area, I see you have backslashes in front of those of quotations, so that's not a problem. But it's still missing an end-parentheses.

-------------------------------

Anyways, besides those syntax errors that are probably non-issues, have you tried printing out $! after those SQL calls? And have you already made a dump of %prog_numbers to make sure it contains valid data?

Another (probably a non-issue) weird thing I see is that you're using '$mtime' as a column name, is that intended? Is the column name not static?

Last edited by Araex : 03-24-2008 at 05:56 PM.
Araex is offline   Reply With Quote
Old 03-24-2008, 11:27 PM   #3 (permalink)
Seths
Registered User
 
Seths's Avatar
 
Join Date: Jul 2006
Posts: 357
+3 Internets
sorry ya the syntax is right in the code just mis wrote it here. I use $mtime since that column varies with each minute of the hour. The %prog_numbers hash has the right information in it. Haven't tried printing out the $! though so I'll try that tomorrow.
Seths is offline   Reply With Quote
Old 03-26-2008, 01:38 AM   #4 (permalink)
gremlinz273
a Menace
 
gremlinz273's Avatar
 
Join Date: Feb 2006
Posts: 614
Post

I assume you have checked to ensure $ldb is actually connecting to the db.

throw this in there and see if it helps:

Code:
foreach $key1(keys(%prog_numbers)) { $update = $ldb->prepare ( "UPDATE LOW_PRIORITY $ldbtable". " SET $mtime=\"$prog_numbers{$key1}\"". " WHERE software=\"$key1\"" ) or die "Couldn't prepare statement: " . $ldb->errstr(); $showfail = $update->execute or die "Cannot execute: " . $update->errstr(); $update->finish(); }
__________________
gremlinz273 is offline   Reply With Quote
Old 03-26-2008, 10:23 AM   #5 (permalink)
Seths
Registered User
 
Seths's Avatar
 
Join Date: Jul 2006
Posts: 357
+3 Internets
Ya its properly connecting. I put in $showfail to check to see if the update failed by doing an If statement like

Code:
if($showfail == 0) { print "Update failed on $ldbtable at $localtime\n"; }
I've also tried using the trace feature in the DBI module and dumping the trace to a log file but as far as I can tell from that its not showing me the reason for the failure to update.
Seths is offline   Reply With Quote
Old 03-26-2008, 11:47 AM   #6 (permalink)
gremlinz273
a Menace
 
gremlinz273's Avatar
 
Join Date: Feb 2006
Posts: 614
Arrow

Well, if you print out $ldb->errstr, it should give you an immediate reason for the failure. The error text might also be in $!, not sure.

If there is no db failure, than the error is most likely in the UPDATE statement. Do SELECT statements work?

print out the sql command.

Code:
my $sql = "UPDATE LOW_PRIORITY $ldbtable". " SET $mtime="$prog_numbers{$key1}"". " WHERE software="$key1""; warn "DEBUG: $sql\n";
As a side note $showfail is only valid on the last iteration of that for loop. Try this instead:

Code:
$showfail = 1; foreach $key1(keys(%prog_numbers)) { ... $showfail &= $update->execute; ... } if(!$showfail) { print "Update failed on $ldbtable at $localtime\n"; }
This will ignore errors on any single UPDATE, and continue the loop through the rest of the updates. Seems a little dirty, but this might actually be what you want.
__________________
gremlinz273 is offline   Reply With Quote
Old 03-26-2008, 04:43 PM   #7 (permalink)
Seths
Registered User
 
Seths's Avatar
 
Join Date: Jul 2006
Posts: 357
+3 Internets
Thank you for all the help. I finally found out the source of the problem, the program list that I was using as the master list had hidden windows characters in them since they were created on a Windows text editor that Linux doesn't see. So that extra ^M character at the end of each line was causing all matches and updates to fail since they didn't match the program name in the DB.
Seths is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
uberguilds network



All times are GMT -7. The time now is 01:28 AM.


Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC6