Stuart White wrote:

> Here's 25 lines of sample input:
> ------------------
> Spurs 94, Suns 82
> 4/29/2003 SBC Center, San Antonio, TX
> Officials: #16 Ted Bernhardt , #33 Sean Corbin , #15
> Bennett Salvatore
> 1st Period

...

> (11:23) [SAN 2-0] Bowen Jump Shot: Made (2 PTS)
> Assist: Parker (1 AST)
> (11:10) [PHX] Marbury Jump Shot: Missed
> ...

Looks like a major task of parsing here.  More than that, it branches into AI,
since it requires major sensitivity to contextual cues.

> ------------
>
> The big picture is creating a box score.  the
> categories are points, offensive rebounds, defensive
> ...
> I plan on getting to the end by writing small programs
> that parse the lines for the different categories.

There is a better way.  Writing separate programs requires shelling out to
communicate between them.  Very inflexible.  I would recommend instead that you
learn about the use of subroutines.

 As you take on complex tasks, you will benefit by writing compact, mofular
subroutines to handle processes at any particular level of abstraction.  To use
subroutines well, you of course must be comfortable with the use of references.

With these two tools available, you will be well-equipped to taake on
object-oriented programming.  I see this as the point where you would want to
branch out to multi-file programming.  I have the feeling that by the time you
have a good solution to this problem, you may need to develop some
representative objects, since it is not a trivial task.

>
> Then, I plan on putting them all together, either as
> includes

C includes, Perl uses

> into one main,

No main in Perl, unless you define and explicitly call it.

> or cutting and pasting them
> into one file.  I expect to use a lot of regular
> expressions to parse the files, and some hashes,
> arrays, and perhaps a bit more complex data structures
> like ArraysOfArrays, or HashesOfHashes, to store the
> information.

Please slow down a bit here.  Not that all these tools may not be called upon
along the way, but this point is first to define the needed outcome, and then
choose the tools needed at any stage along the way.   The sample data you posted
included a number of different types of information, each of which probably
calls for special handling.  Have you enumerated the specific types of
information contained?  You will probably need to do so.

A well-named set of subroutines can make the task much easier.  Something like--

my $box_score_ref = PlayByPlay->new('Lakers', 'Suns', 'Phoenix', '01/25/2004');

open PLAYS, 'play_by_play.txt' or die "couldn't open raw report: $!";
while (my $line = <PLAYS>) {
    if (my $shot = shot_taken($line)) {
       record_shot($shot);
   } elsif (my $penalty = penalty_on_play($line)) {
      reord_penalty($penalty);
   } eslif ...

which will give you a great deal of lexibility in handling the differnt kinds of
data and formats that these reports are throwing at you.

> Does that help?

You tell us.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to