Stuart White wrote:

> Wow, yeah that helps a lot.
> Here's a question: If if had:
> $line = 'Spurs 94, Suns 82, Heat 99, Magic 74'
>  and then did a split on comma and comma's surrounding
> spaces:
> @result = split (/\s*,\s*/, $line);

result?  How specific is "result" to the issue at hand?  Would not $score

>
> then @result would look like this, right?
> @result[0] = 'Spurs 94'

You should know better than this by now, with the help you've been getting.
With that @ symbol, you are referring to a slice--an array of one element.  ***
When you are referring to a scalar, use the scalar symbol $ ***

>
> @result[1] = 'Suns 82'

These first two make sense, pretty much.  I think this is one place where $team1
and $team2 might be more sensible, though it is even better, if there is some
order to which team is listed first in the pairing, to have you identifier
reflect that order, say $home_team and $visitor [if these are accurate of
course]

>
> @result[2] = 'Heat 99'

Going on to load more elements into the array does not make sense..  Does your
data come in one continuous line, just a long string of team names separated by
commas?  My impression is that it came line by line.  There would be no sense in
doing the work of the split only to throw everything back in the same pile.
There are a lot of different things you could do here, but the sensible ones
would indicate that you should do something with the stats for each pairing
before you go on to the next line.


>
> @result[3] = 'Magic 74'
>
> If I wanted to split on the numbers as well, why
> doesn't this work:
> @result = split (/\s*\d*,\s*\d*/, $line);

The previous post already explained this, and you have seen the result of what
you are trying.  You can't do that because the information disappears if you use
it in the split expression.

Splitting the lines into a pair of team-score combinations is one step.  It
deserves a line of its own.
Extracting the name and score from each team-score clause is another step that
deserves a line or three of its own.

>
>
> I just had a thought, it have to look more like:
> @result = split (/(\s*|\d*),\s*\d*/, $line);

Unless there is a compelling reason why you must do all your regex work for a
line in one pass, you are better off not doing so.

Though its Perl implementation is highly efficient, the regex process is very
costly, and the cost rises much more through complexity of expression than
through multiple runs.

Please review
perldoc -f split
for a better understanding.  The split regex, is *what gets thrown away*.  Do
not put any data you may need in it.

I think an earlier poster may have confused the issue with the zero-or-more
spaces before the comma.  Unless the file format is very sloppy, this should not
be necessary.  Assume decent data,
split /,\*/, $line;
should split a line into its comma delimited elements.  Nor reason to try to get
fancy here.  Just split on the comma to get two elements.

>
> I'm confusing myself, but when I get home, I'll try
> out what you've shown me.  That might be the way to do
> it.
>

Keep it grounded--by choosing identifiers carefully to always communicate
clearly what information they hold
Keep it simple--most things are, if you let them be.
Do one thing per line until you are using all of the basic constructs fluently.
Pay close attention to the nature of each thing you are using a variable to
describe, and make the containment class symbol [$, @, or %] that you use,
reflects accurately whether you are referring to a container, or to an element
held in the container.

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