in reply to Re^2: Perl Program - Out of memory?
in thread Perl Program - Out of memory?
A couple of more obvious errors were fixed, too. Please check that the code still behaves the same.
You really ought to use warnings at the very least; it might provide pertinent clues to the issue.
I bet BrowserUK can replace those ten nested loops with equivalent permutation logic, in twenty lines :)#USAGE EXAMPLE - Max Points Replaced If Higher Value Found require 'funcs_top10.pl'; # use warnings; $delay = 3; $maxSalary = 100000; $programStartTime = localtime(); $qbHash = getStats("QB"); #Sorts Player Statistics Into Hashes Accordi +ng To Position $rbHash = getStats("RB"); $wrHash = getStats("WR"); $teHash = getStats("TE"); $dstHash = getStats("DST"); $flHash = getFlexStats(); foreach $key(sort keys %$qbHash) { $QB1i = $qbHash->{$key}->{PlayerID}; $QB1s = $qbHash->{$key}->{Salary}; $QB1p = $qbHash->{$key}->{FPPG}; $QB1pos = $qbHash->{$key}->{Position}; #print "QB1 count = $qb1count \n"; #$qb1count++; foreach $key(sort keys %$qbHash) { $QB2i = $qbHash->{$key}->{PlayerID}; $QB2s = $qbHash->{$key}->{Salary}; $QB2p = $qbHash->{$key}->{FPPG}; $QB2pos = $qbHash->{$key}->{Position}; #print "--QB2 count = $qb1count \n"; #$qb2count++; next if $QB1i == $QB2i; foreach $key(sort keys %$rbHash) { $RB1i = $rbHash->{$key}->{PlayerID}; $RB1s = $rbHash->{$key}->{Salary}; $RB1p = $rbHash->{$key}->{FPPG}; $RB1pos = $rbHash->{$key}->{Position}; #print "----RB1 count = $rb1count \n"; #$rb1count++; foreach $key(sort keys %$rbHash) { $RB2i = $rbHash->{$key}->{PlayerID}; $RB2s = $rbHash->{$key}->{Salary}; $RB2p = $rbHash->{$key}->{FPPG}; $RB2pos = $rbHash->{$key}->{Position}; #print "------RB2 count = $rb2count \n"; #$rb2count++; next if $RB1i == $RB2i; foreach $key(sort keys %$wrHash) { $WR1i = $wrHash->{$key}->{PlayerID}; $WR1s = $wrHash->{$key}->{Salary}; $WR1p = $wrHash->{$key}->{FPPG}; $WR1pos = $wrHash->{$key}->{Position}; #print "--------WR1 count = $wr1count \n"; # $wr1count++; foreach $key(sort keys %$wrHash) { $WR2i = $wrHash->{$key}->{PlayerID}; $WR2s = $wrHash->{$key}->{Salary}; $WR2p = $wrHash->{$key}->{FPPG}; $WR2pos = $wrHash->{$key}->{Position}; next if $WR1i == $WR2i; foreach $key(sort keys %$teHash) #TE1 Start { $TE1i = $teHash->{$key}->{PlayerID}; $TE1s = $teHash->{$key}->{Salary}; $TE1p = $teHash->{$key}->{FPPG}; $TE1pos = $teHash->{$key}->{Position}; foreach $key(sort keys %$dstHash) #DST Sta +rt { $DSTi = $dstHash->{$key}->{PlayerID}; $DSTs = $dstHash->{$key}->{Salary}; $DSTp = $dstHash->{$key}->{FPPG}; $DSTpos = $dstHash->{$key}->{Position} +; foreach $key(sort keys %$flHash) #FL1 +Start { $FL1i = $flHash->{$key}->{PlayerID +}; $FL1s = $flHash->{$key}->{Salary}; $FL1p = $flHash->{$key}->{FPPG}; $FL1pos = $flHash->{$key}->{Positi +on}; next unless (($FL1i != $RB1i) && ( +$FL1i != $RB2i) && ($FL1i != $WR1i) && ($FL1i != $WR2i) && ($FL1i != +$TE1i)); foreach $key(sort keys %$flHash) # +FL2 Start { $FL2i = $flHash->{$key}->{Play +erID}; $FL2s = $flHash->{$key}->{Sala +ry}; $FL2p = $flHash->{$key}->{FPPG +}; $FL2pos = $flHash->{$key}->{Po +sition}; next unless (($FL2i != $RB1i) +&& ($FL2i != $RB2i) && ($FL2i != $WR1i) && ($FL2i != $WR2i) && ($FL2i + != $TE1i) && ($FL1i != $FL2i)); ############################## +################################# $newMaxSalary = $QB1s + $QB2s ++ $RB1s + $RB2s + $WR1s + $WR2s + $TE1s + $FL1s; $newMaxPoint = $QB1p + $QB2p + + $RB1p + $RB2p + $WR1p + $WR2p + $TE1p + $FL1p; next unless $newMaxSalary < $m +axSalary; #print "Current Salary = " . $ +newMaxSalary . "\n"; if (!$maxPoint) { $maxPoint = $newMaxPoint; next; } next unless $maxPoint < $newMa +xPoint; $maxPoint = $newMaxPoint; print "New Max Points Reached! + " . $maxPoint . "\n"; print "Here is your team! \n"; print "QB1 = " . $QB1i . "\n"; print "QB2 = " . $QB2i . "\n"; print "RB1 = " . $RB1i . "\n"; print "RB2 = " . $RB2i . "\n"; print "WR1 = " . $WR1i . "\n"; print "WR2 = " . $WR2i . "\n"; print "TE1 = " . $TE1i . "\n"; print "FL1 = " . $FL1i . "\n"; print "FL2 = " . $FL2i . "\n"; print "DST = " . $DSTi . "\n"; print "*********************** +******************** \n \n"; sleep($delay); ############################## +###################################### }#FL2 End }#FL1 End }#DST End }#TE1 End }#WR2 End }#WR1 End }#RB2 End }#RB1 End }#QB2 End }#QB1 End print "--------------- Projected Team Points = $maxPoints ------------ +--\n"; print '$$$$$$$$$$$$$$$ Projected Team Salary = '.$salary.' $$$$$$$$$$$ +$$$$' . "\n\n"; $programStopTime = localtime(); print "Program Start Time - $programStartTime, Program Stop Time - $pr +ogramStopTime \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl Program - Out of memory?
by jdlev (Scribe) on Nov 15, 2013 at 22:11 UTC |