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);



--
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