•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,759 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1493 | Replies: 10 | Solved
![]() |
•
•
Join Date: Sep 2005
Location: St. Louis
Posts: 145
Reputation:
Rep Power: 4
Solved Threads: 0
I'm writing to a file. There are only ten items able to be written to the file (game scores, test results, whatever). I'm using a drop-down selection list on the form to tell which number is being submitted. Is there any way to have it checked as the page loads what numbers have been submitted and omit them from the selection list? (Say numbers 1, 2, 4, and 8 have been submitted; then only 3, 5, 6, 7, 9, & 10 would be available.)
Also, how would I go about averaging something already submitted into the file with new data as it comes in? (An item that cost $2 is already in the file. An item that costs $1 is submitted. I want the average of $1.50 outputted. How would I accomplish this?)
Also, how would I go about averaging something already submitted into the file with new data as it comes in? (An item that cost $2 is already in the file. An item that costs $1 is submitted. I want the average of $1.50 outputted. How would I accomplish this?)
•
•
Join Date: Oct 2007
Posts: 302
Reputation:
Rep Power: 2
Solved Threads: 29
Hi,
I'm not sure I follow on the first one, but for the second part, this might help:
$already_putin=2.00 # use 0 to start;
$input = 1.00;
$mean_average = ($already_putin+$input)/2;
I'm not sure I follow on the first one, but for the second part, this might help:
$already_putin=2.00 # use 0 to start;
$input = 1.00;
$mean_average = ($already_putin+$input)/2;
•
•
•
•
I'm writing to a file. There are only ten items able to be written to the file (game scores, test results, whatever). I'm using a drop-down selection list on the form to tell which number is being submitted. Is there any way to have it checked as the page loads what numbers have been submitted and omit them from the selection list? (Say numbers 1, 2, 4, and 8 have been submitted; then only 3, 5, 6, 7, 9, & 10 would be available.)
Also, how would I go about averaging something already submitted into the file with new data as it comes in? (An item that cost $2 is already in the file. An item that costs $1 is submitted. I want the average of $1.50 outputted. How would I accomplish this?)
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
•
•
Join Date: Sep 2005
Location: St. Louis
Posts: 145
Reputation:
Rep Power: 4
Solved Threads: 0
Keep in mind that the code is in no manner complete.
If it's possible (and I honestly have no clue if it is or not) I'd like to verify before this page loads whether or not Week 1, Week 2, etc. has been selected. If so, either not allow it to be shown in the selection list, or at least give an error message saying that "this week already has data submitted please select another" type of thing.
Also, it needs to be able to store the data submitted and provide totals and averages of some of it.
If it's possible (and I honestly have no clue if it is or not) I'd like to verify before this page loads whether or not Week 1, Week 2, etc. has been selected. If so, either not allow it to be shown in the selection list, or at least give an error message saying that "this week already has data submitted please select another" type of thing.
Also, it needs to be able to store the data submitted and provide totals and averages of some of it.
#!C:/Perl/bin/perl.exe
#Football Stats
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use strict;
use SDBM_File;
use Fcntl;
##########variable declarations and input assignments#############################
my ($weekNum, $whereAt, $homeCounter, $AwayCounter, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $homeCount, $awayCount
$sacks, $sacksAllowed, $turnovForcedPerGame, $turnovAllowedPGame, $tds, $tdsAllowed, $passYrdTotal, $passYrdAvg, $rushYrdTotal,
$rushYrdAvg, $sacksTotal, $sacksPerGameAvg, $sacksAllowedTotal, $sacksAllowedAvg, $turnovForcedTotal, $turnovForcedAvg,
$turnovAllowedTotal, $turnovAllowedAvg, $tdsTotal, $tdsAvg, $tdsAllowedTotal, $tdsAllowedAvg, $wins, $losses, $winPercent,
$winPercentHome, $winPercentAway, $winLose,);
$weekNum = param('weekNum');
$whereAt = param('gamePlayed');
$yourTmScore = param('yourTmScore');
$otherTmScore = param('otherTmScore');
$passYrdPGame = param('passYrdPGame');
$rushYrdPGame = param('rushYrdPGame');
$sacks = param('sacks');
$sacksAllowed = param('sacksAllowed');
$turnovForcedPerGame = param('turnovForcedPerGame');
$turnovAllowedPGame = param('turnovAllowedPGame');
$tds = param('tds');
$tdsTotal = 0;
$tdsTotal = $tds + $tdsTotal;
$tdsAvg =
$tdsAllowed = param('tdsAllowed');
$tdsAllowedTotal = $tdsAllowed + $tdsAllowedTotal;
$tdsAllowedAvg =
$rushYrdTotal = $rushYrdPGame + $rushYrdTotal;
$rushYrdAvg =
$passYrdTotal = $passYrdPGame + $passYrdTotal;
$passYrdAvg =
########save to file#######################################
open(OUTFILE, ">>","nflStats.txt")
or die "Error opening nflStats.txt $!, stopped";
print OUTFILE join(':::',
$weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
$turnovAllowedPGame, $tds, $tdsAllowed), "\n";
close(OUTFILE);
#calculate stats
open(INFILE, "<", "nflStats.txt");
while(<INFILE>) {
my ($weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
$turnovAllowedPGame, $tds, $tdsAllowed) = split(':::');
############################### do calculations####################################
if ($yourTmScore > $otherTmScore) {
$wins = $wins + 1;
}
else {
$losses = $losses + 1
}
}
if ($whereAt = "Home") {
$homeCount = $homeCount +1;
}
else if {
($whereAt = "Away") {
$awayCount = $awayCount + 1;
}
close INFILE;
#generate page
print <<printHTML;
<html>
<head><title>Current Cowboys Statistics</title></head>
<body bgcolor="#CCCCCC">
<font size="3">Week $weekNum :<br />Played at: $whereAt<br /></font>
</body></html>
printHTML;•
•
Join Date: Sep 2005
Location: St. Louis
Posts: 145
Reputation:
Rep Power: 4
Solved Threads: 0
I have all of the errors fixed except one. It keeps telling me that it can't find endHTML string terminator before EOF. I don't know why I'm getting this one.
#!C:/Perl/bin/perl.exe
#Football Stats
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use strict;
use SDBM_File;
use Fcntl;
##########variable declarations and input assignments#############################
my ($weekNum, $whereAt, $homeCounter, $AwayCounter, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $homeCount, $awayCount,
$turnovAllowedPGame, $tds, $tdsAllowed, $passYrdTotal, $passYrdAvg, $rushYrdTotal,
$rushYrdAvg, $sacksTotal, $sacksPerGameAvg, $sacksAllowedTotal, $sacksAllowedAvg, $turnovForcedTotal, $turnovForcedAvg,
$turnovAllowedTotal, $turnovAllowedAvg, $tdsTotal, $tdsAvg, $tdsAllowedTotal, $tdsAllowedAvg, $wins, $losses, $winPercent,
$winPercentHome, $winPercentAway, $winLose,);
my $weekNum = param('weekNum');
my $whereAt = param('gamePlayed');
my $yourTmScore = param('yourTmScore');
my $otherTmScore = param('otherTmScore');
my $passYrdPGame = param('passYrdPGame');
my $rushYrdPGame = param('rushYrdPGame');
my $sacks = param('sacks');
my $sacksAllowed = param('sacksAllowed');
my $turnovForcedPerGame = param('turnovForcedPerGame');
my $turnovAllowedPGame = param('turnovAllowedPGame');
my $tds = param('tds');
my $tdsTotal = 0;
my $tdsTotal = $tds + $tdsTotal;
my $tdsAvg = '';
my $tdsAllowed = param('tdsAllowed');
my $tdsAllowedTotal = $tdsAllowed + $tdsAllowedTotal;
my $tdsAllowedAvg = '';
my $rushYrdTotal = $rushYrdPGame + $rushYrdTotal;
my $rushYrdAvg = '';
my $passYrdTotal = $passYrdPGame + $passYrdTotal;
my $passYrdAvg = '';
########save to file#######################################
open(OUTFILE, ">>","nflStats.txt")
or die "Error opening nflStats.txt $!, stopped";
print OUTFILE join(':::',
$weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
$turnovAllowedPGame, $tds, $tdsAllowed), "\n";
close(OUTFILE);
#calculate stats
open(INFILE, "<", "nflStats.txt");
while(<INFILE>) {
my ($weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
$turnovAllowedPGame, $tds, $tdsAllowed) = split(':::');
############################### do calculations####################################
if ($yourTmScore > $otherTmScore) {
$wins = $wins + 1;
}
else {
$losses = $losses + 1
}
}
if ($whereAt = "Home") {
$homeCount = $homeCount +1;
}
elsif ($whereAt = "Away") {
$awayCount = $awayCount + 1;
}
close INFILE;
#generate page
print <<endHTML;
<html>
<head><title>Current Cowboys Statistics</title></head>
<body bgcolor="#CCCCCC">
<font size="3">Week $weekNum :<br />Played at: $whereAt<br /></font>
</body></html>
endHTML Don't bother with heredocs, they are just too perl 4, use an appropriate quote operator like qq:
#generate page
print qq{
<html>
<head><title>Current Cowboys Statistics</title></head>
<body bgcolor="#CCCCCC">
<font size="3">Week $weekNum :<br />Played at: $whereAt<br /></font>
</body></html>
};![]() |
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- how can i extract data from .xml file? (Visual Basic 4 / 5 / 6)
- file on acess in real time (Visual Basic 4 / 5 / 6)
- Need help with CPU scheduling algorithms (C++)
- Creation and concurrent execution of processes (C)
- Broken Folder Icon OSX 10.04 Startup (OS X)
- Tutorials for Linux (*nix Software)
Other Threads in the Perl Forum
- Previous Thread: PROCESS CHECKING PROBLEM using PERL
- Next Thread: Script only displaying last entries made


Linear Mode