--- "Charles K. Clarkson" <[EMAIL PROTECTED]> wrote: > Stuart White <[EMAIL PROTECTED]> wrote: > : > : I figured the small snippets, how to > : print an array, how to split a string etc., was > : better as it was more focused, and would apply > : to not just the one example. > > That's a great way to break the program down, > but > over the years I have found that many beginners are > asking the wrong question. Supplying a good answer > to the wrong question doesn't usually help much. > With > just a bit more information, I can tell whether the > question is the right one and whether I should > invest > my time in it or not.
Sure, I agree with that. > > For example, here's your parsing sub: > > sub ParseLineForHomeAndVisitors() > { > if ($_ > =~/Spurs|Suns|Mavericks|Lakers|Clippers|Cavaliers|Celtics| > Pacers|Pistons|Wizards|Warriors|Bulls|Hawks|Raptors|Magic| > Heat|Kings|Rockets|Nuggets|Grizzlies|Jazz|Knicks|Nets| > Supersonics|'Trail > Blazers'|Bucks|Timberwolves|Hornets| > Sixers|Bobcats)/) > { > @teams = /([[:alpha:]]+)/g; > } > return (@teams); > } > > The 'if' statement is doing 3 suspicious things. > One, > it is capturing the match. Two, I suspect 'Trail > Blazers' > in single quotes will never be found. And it is not > obvious what happens if there is no match. It looks > like > @teams is a global variable, but since that is a Bad > Thing, I would hope you weren't using it. > 1)Well, I want it to capture the match. 2)Are you suspicious because Trail Blazers is in single quotes, or because it might be 'Trail' or 'Blazers'? If it's the latter, no need for suspicion because it will only show up as 'Trail Blazers.' If it is the former, then there is something I'm missing in my understanding of single and double quotes. 3)Well, I've been taught not to use global variables, unless I have to, and I was then taught that I should not have to, not at the level I was programming at, so it's not my intention to use a global variable. What is not shown in the code above is where I declare my @teams; >From my understanding of Perl, that makes the variable local, right? > More importantly, (IMO) the sub probably > shouldn't be > doing the line validation. That should be done to > determine > if this sub should be called. I think I see what you mean, but I think that the purpose of the sub IS to find that line, and extract the teams from it and then put them into an array where I can then call them as scalars, ($teams[0] and $teams[1]). >I could write a nice > long > answer about this sub, but I'd probably be answering > the > wrong question. > Entirely possible. I try my best to write clearly what I know or think I know, what I want the code to do, what I think the code is doing, and what my end goal is, but sometimes, I don't include the end goal, and sometimes I get tired of detail. > > : 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 > : (12:00) Jump Ball Robinson vs Williams > : (11:41) [PHX] Marion Turnaround Jump: Missed > [snip] > : ------------ > > Thanks. Is each input example like this.? Yes, in form. Not literally. For example, line one might be in a different file: Mavericks 119, Heat 99 > Is there > a chance that a second line like "Spurs 94, Suns 82" > will show up? Not in the same file. That line shows up only once, and only at the top. There might be one or two insignificant lines above that one in all the files, but, as I've no use for those lines, I didn't paste them over here. >Or will it be in a different dataset > (file, recordset, etc.)? There certainly could be one, and only one other file that looks exactly like that, as in the same score, and the same order of teams. However, the likelihood of that happening is very small. It is likely however to have this line: Spurs 120, Suns 100 or Spurs 83, Suns 77 and in fact, there will be another file that has the teams in the same order, but the scores are likely to be different. However, in any one file, there will only be ONE line that looks like that. > > The reason I ask Is that there is probably a > better > way to pick this line out of the file than that it > contains team names. For example, it seems to be the > only line that will match > /[[:alpha:]]+\s+[[:digit:]]+,/. > It also seems to be the first line. Is it always the > first line? > Once I've extracted the two lines of insignificance, then yes, it will always be the first line. And I agree, there ought to be an easier way. The reason I wrote this particular sub was because at the end of the program, for a test,(and eventually not a test, but a significant part of the program) I wanted to print out the rosters of the two teams, which I've done, but I also wanted to print the teams nicknames, and not have to hardcode that into every program. this entailed linking the nicknames to the abbreviations (SAN, PHX) because, as you'll notice, there's no way of telling a computer that SAN and Spurs are basically one in the same. So I thought I'd tell it that by setting up a hash. but I do think that there is an eaiser way, or a lazier way of establishing that relationship. > my $first_line = <DATA>; > my @teams = $first_line =~ /([[:alpha:]]+)/g; > > That looks like it'd work. And wow, that's a lot less work. > As I progress with my own skills I find that > programming is just manipulating of one form of data > to > another form. I haven't really learned more about > perl > in the last year, I've learned more about pattern > recognition and how to apply it to the data coming > in > and leaving my scripts. > That's how I think of perl because, as you might see, this program is about text manipulation: taking sentences and turning them into 'blocks' of information. > I have also find that the better idea of what > the output should be, the easier (and faster) I can > create the solution. > Makes complete sense. And I have a firm grasp on what I want to do conceptually, it's the minutia, the nuts and bolts that presently is standing in my way. > > : The big picture is creating a box score. > > I have no idea what a box score is. I am sports > deficient and only know this is basketball because > of the categories you mention. > Go here: http://www.nba.com/games/20040317/ATLDAL/boxscore.html and see the box score of my beloved mavericks losing to the horrid hawks. :( The box score is the set of both teams play. It's a numerical summary of what occurred during the game. player names are in rows, statistics are in columns. statistics have funny abbreviations too. Does it make sense now? Here's even an example that might be easier to understand. You go to the grocery store knowing that you need to get apples(points), oranges(assists), bananas(rebounds), and loaves of bread(blocks). You want to get some of all of them, but you might only get a lot of apples and bananas. You shouldn't get twinkies because you are on a diet, but you just might(turnovers), and you absolutely should not get ice cream, unless either you're careless and do so, or it's an emergency situation(fouls). So you go to the store and when you get home you tally up what happened: 12 apples 6 bananas 3 oranges 0 loaves of bread (couldn't find it) 2 twinkies (they looked so good) 5 pints of ice cream(serious craving) If you just told me that's what you bought, I could get a picture of what happened at the store. Maybe apples were on sale(no one was defending you from scoring), and bananas were too, but some were overripe, so you only got six, you're not really an orange kind of guy, but you know you ought to have them, so you got three, and there was not opportunity to get bread, so you got none. your mind was wandering which caused you to succumb and get twinkies, and maybe ice cream was $.02 a pint, you had a huge craving, your favorite kind which you had not seen in months was there, or someone else put them in your cart. That might confuse you even more, but the idea is that there is a game or a grocery trip, and one can look at the box score or the items in the grocery bag, and know 1)what you did, or what you bought and how much, 2)assume what might have caused you to do this or buy that. The best way to sum it up is its a numerical summary. Does that explain it? > > : the categories are points, offensive rebounds, > : defensive rebounds, assists, steals, turnovers, > : field goals attempted, field goals made, blocks > : and fouls. > > There are "field goals" in basketball?!? > > Yup. Semantics. A field goal is just the act of the ball going through the hoop...that is when it's not a free throw. Field goals are scores. I understand the confusion as they play on a court, not a field, but I don't make the rules, I just follow them. :) __________________________________ Do you Yahoo!? Yahoo! Mail - More reliable, more storage, less spam http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>