On Jun 21, 3:30 am, chas.ow...@gmail.com ("Chas. Owens") wrote: > On Sun, Jun 20, 2010 at 20:49, C.DeRykus <dery...@gmail.com> wrote: > > On Jun 19, 5:07 pm, stu21...@lycos.com wrote: > >> I have some text that specifies inherited runners in baseball: > > >> 'Hughes, D 2-0, O'Flaherty 2-0, Moylan 1-1' > > >> I want to split on the comma and associate the numbers with that player. > >> The > >> problem is that sometimes the player's first initial is used sometimes not. > >> Is there a clever way to consider the comma part of the name when an > >> initial > >> is used and a delimiter otherwise? Thanx > > > Another possible option maybe: > > > my %runners = split / ([0-9]+-[0-9]+) /x, $s; > > snip > > That is nice, but you can improve it by adding a non-captured group > containing a comma and a whitespace character or the end of the > string. > > ... > > my %runners = split / ( [0-9]+ - [0-9]+ ) (?: , \s | $) /x, $s; > > print Dumper \%runners; >
Yes. That's a key correction. Without the non-capturing group, the comma's get picked up and pre-pended to each player name except the first. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/