I like the idea of using split() but decided to keep most of my regex and incorporate split on the string. So the string: 'Spurs 94, Suns 82' <-and there may or may not be a space after the 2. I decided to read up on split(), and then try to split it. This is what I came up with:
@teamscores = split(m#\s*\d*\,\s*#, $_); This puts 'Spurs' in $teamscores[0] and 'Suns 82' in $teamscores[1]. I think it has to do with the comma not being present after 'Suns' so I modified the split() to look like this: @teamscores = split(m#\s*\d*\,*\s*#, $_); that put 'p' in $teamscores[1] so then I tried to make the comma and the space optional as a group and did this: @teamscores = split(m#\s*\d*(\,\s*)?#, $_); and that gave me a use of uninitialized error with the concatenation operator. I'm not sure what that's about. i tried one more change: @teamscores = split(m#\s*\d*\,?\s?#, $_); Since the comma wasn't present in the second number, and I wasn't sure if the space was either. That didn't give me what I expected. it gave me: $teamscores[0] == S and $teamscores[1] == p I'm not sure what's going wrong here. Can someone tell me how I can split 'Spurs 94, Suns 82' into: array[0] == 'Spurs' and array[1] == 'Suns' Thanks. -stu --- "Randy W. Sims" <[EMAIL PROTECTED]> wrote: > On 3/11/2004 9:01 PM, Stuart White wrote: > > > I'm confused about greediness. > > This is the line that I'm trying to match: > > > > Spurs 94, Suns 82 > > If the line is as above, I probably wouldn't use a > regex. The following > is more verbose, but easier to manage IMHO. > > #!/usr/bin/perl > > use strict; > use warnings; > > my $line = 'Spurs 94, Suns 82'; > > my (%scores); > > my @teamscores = split(/\s*,\s*/, $line, 2); > foreach my $teamscore (@teamscores) { > $teamscore =~ s/^\s+//; $teamscore =~ s/\s+$//; > my ($team, $score) = split(/\s+/, $teamscore, 2); > $scores{$team} = $score; > } > > use Data::Dumper; > print Dumper(\%scores); > > __________________________________ Do you Yahoo!? Yahoo! Search - Find what you’re looking for faster http://search.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>