cjwsb
12-10-2003, 04:48 PM
Hi all,
Perl NEWBIE here. I created a file (that for now is filled with dummy data) called backs.dat. Basically, it just has some information about running backs in the NFL. Here's it contents:
Jerome Bettis PIT 323 1460
Priest Holmes KC 400 1500
Kevin Faulk NE 250 1000
Clinton Portis DEN 300 1200
Eddie George TEN 350 1300
Ahman Green GB 250 900
Each field is seperated by tabs.
I have also created a file called avgs.dat for writing. I am trying to write a script that will open the backs.dat file, reads from it, and mathematically calculates the running back averages, then sends them into the avgs.dat file. I would like any information already in the avgs.dat file to be overwritten. If either operation fails, I want the script to exit with an appropriate error message. Each line read from backs.dat should be separated so that all five fields are stored in separate variables. For each input line, a line of the following form should be output to avgs.dat:
FIRST-NAME LAST-NAME AVG-YDS-PER-CARRY
Note that the AVG-YDS-PER-CARRY is computed as $yards/$carries. For instance, a calculator shows me that the Jerome Bettis answer would be:
Jerome Bettis 4.52012383900929
After backs.dat has been processed in its entirety, both files should be closed. If a close fails, an error message should be produced and the script should exit.
I am having a helluva time figuring this out. I know it's a simple calulation, but I can't seem to even get off the ground. Anyone have any thoughts on this? Could someone show me some code examples, perhaps, that would do this? There's no rush, but it is driving me crazy!
Thanks!
Perl NEWBIE here. I created a file (that for now is filled with dummy data) called backs.dat. Basically, it just has some information about running backs in the NFL. Here's it contents:
Jerome Bettis PIT 323 1460
Priest Holmes KC 400 1500
Kevin Faulk NE 250 1000
Clinton Portis DEN 300 1200
Eddie George TEN 350 1300
Ahman Green GB 250 900
Each field is seperated by tabs.
I have also created a file called avgs.dat for writing. I am trying to write a script that will open the backs.dat file, reads from it, and mathematically calculates the running back averages, then sends them into the avgs.dat file. I would like any information already in the avgs.dat file to be overwritten. If either operation fails, I want the script to exit with an appropriate error message. Each line read from backs.dat should be separated so that all five fields are stored in separate variables. For each input line, a line of the following form should be output to avgs.dat:
FIRST-NAME LAST-NAME AVG-YDS-PER-CARRY
Note that the AVG-YDS-PER-CARRY is computed as $yards/$carries. For instance, a calculator shows me that the Jerome Bettis answer would be:
Jerome Bettis 4.52012383900929
After backs.dat has been processed in its entirety, both files should be closed. If a close fails, an error message should be produced and the script should exit.
I am having a helluva time figuring this out. I know it's a simple calulation, but I can't seem to even get off the ground. Anyone have any thoughts on this? Could someone show me some code examples, perhaps, that would do this? There's no rush, but it is driving me crazy!
Thanks!