in reply to problems splitting string
This will do the trick:
my $string = '1 Cat 2 Dogs 3 Hamsters'; my @a = $string =~ m/\b\d+\s+\w+\b/g; use Data::Dumper; print Dumper \@a; __END__ $VAR1 = [ '1 Cat', '2 Dogs', '3 Hamsters' ];
Update: if you want to push, try this:
my $string = '1 Cat 2 Dogs 3 Hamsters'; my @a; push @a, $1 while $string =~ m/(\b\d+\s+\w+\b)/g; use Data::Dumper; print Dumper \@a; __END__ $VAR1 = [ '1 Cat', '2 Dogs', '3 Hamsters' ];
--
David Serrano
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problems splitting string
by ikegami (Patriarch) on Dec 15, 2005 at 16:12 UTC | |
by Anonymous Monk on Dec 15, 2005 at 18:04 UTC | |
by Roy Johnson (Monsignor) on Dec 15, 2005 at 18:08 UTC |