I have a Perl script that runs every 15 minutes off of a shell off of a cron. It goes through every member in my database and increases their HP by 15%
So I made this script with help from the people in this forum, but in the past two or three weeks it has been either been skipping over people, or it hasnt been getting to the end of the table, and I dont know why its doing this
hpup.pl
Any help would be greatly appreciated
So I made this script with help from the people in this forum, but in the past two or three weeks it has been either been skipping over people, or it hasnt been getting to the end of the table, and I dont know why its doing this
hpup.pl
Code:
#!/usr/bin/perl
# PERL MODULE WE WILL BE USING
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}
use DBI;
print "Content-type: text/html \n\n";
# MySQL CONFIG VARIABLES
$host = "localhost";
$database = "*******";
$tablename = "users";
$user = "*********";
$pw = "**********";
# PERL MYSQL CONNECT
$connect = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $pw, {RaiseError => 1});
$sth = $connect->prepare("SELECT * FROM users");
$sth->execute() or die $dbh->errstr;
while ($ref = $sth->fetchrow_hashref()) {
my $add = $ref->{'maxhp'} * .15;
my $hp = $ref->{'hp'} + $add;
$hp = int($hp);
if($hp > $ref->{'maxhp'}){
$hp = $ref->{'maxhp'};
}
my $myquery = $connect->prepare("UPDATE users SET hp = '$hp' WHERE username = '$ref->{'username'}'");
#myquery = "INSERT INTO $tablename (hp) VALUES ($hp)";
$myquery->execute();
}
Any help would be greatly appreciated
Last edited: