in reply to splitting punctuation in a text
If you have capturing parentheses in the regex in split, the stuff in there comes out in the resulting list.
use Data::Dumper; my $s = 'earth, wind & fire'; my @out = split /\s*([,&])\s*/, $s; print Dumper \@out; __END__ $VAR1 = [ 'earth', ',', 'wind', '&', 'fire' ];
Of course, make "[,&]" the class of punctuation you actually care about.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting punctuation in a text
by Your Mother (Archbishop) on Aug 11, 2008 at 17:38 UTC |