jmrhide-p...@yahoo.com wrote:
Hi, and thanks for volunteering to help!
I installed the following script last year and it seemed to be working fine.
Yesterday, however, my hosting service took down my site because the script was
tying up so much of their server resources that it was a threat to their
business. One of the folks I talked to there said he thought it was starting
multiple copies of itself that were never terminated. The logs didn't show the
script being accessed more than a few times a day on average.
I would appreciate help debugging this thing:
[ snip ]
# LOAD DATA
open FH, "/home1/theinfp0/public_html/psychdef/tutorial.fil" or die $!;
while (<FH>) {
if ($topic eq "REVIEW") { $termnum[$ops++] = $_; }
elsif (/$topic/) { $termnum[$ops++] = $_; }
}
close FH;
$defnum = $ops; # NUMBER OF TERMS IN DATA SET
# PARSE $_ TO GET $term(32) $cat(16) $def(64) $story(128) via @data:
$ops = 0;
foreach (@termnum) {
@data = /(.{16})/g;
$cat[$ops] = $data[0];
$term[$ops] = $data[1].$data[2];
$def[$ops] = $data[3].$data[4].$data[5].$data[6];
$story[$ops] =
$data[7].$data[8].$data[9].$data[10].$data[11].$data[12].$data[13].$data[14];
# RIGHT TRIM STRINGS
$cat[$ops] =~ s/\s+$//;
$term[$ops] =~ s/\s+$//;
$def[$ops] =~ s/\s+$//;
$story[$ops++] =~ s/\s+$//;
}
A Perl programmer might write that like:
# LOAD DATA
open FH, "/home1/theinfp0/public_html/psychdef/tutorial.fil" or die $!;
while (<FH>) {
if ($topic eq "REVIEW") { push @termnum, $_; }
elsif (/$topic/) { push @termnum, $_; }
}
close FH;
$defnum = @termnum; # NUMBER OF TERMS IN DATA SET
# PARSE $_ TO GET $term(32) $cat(16) $def(64) $story(128) via @data:
foreach (@termnum) {
my @data = unpack 'A16 A32 A64 A128', $_;
push @cat, $data[ 0 ];
push @term, $data[ 1 ];
push @def, $data[ 2 ];
push @story, $data[ 3 ];
}
# EVALUATE RESPONSE AND PROVIDE FEEDBACK, ADJUSTING SCORES
if ($answer and ($answer ne $goodans)) { $answer = 0; }
if ($answer) {
$smarts++;
$score = ++$score + $playlevel;
Using auto-increment or auto-decrement on a variable that appears more
than ONCE in an expression will result in UNDEFINED behavior.
What did you expect the value of $score to be after this expression?
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/