in reply to 30 Spaces- 1 question
My recommendation:
my @w = split /\s+/,$text,31; pop @w; my $words30= join " ", @w;
dchetlin's regex I like too: (I modified it a little)
$text =~ m/^((?:\S+\s+){1,30})/; my $words30 = $1;
Tho with that all the usual warnings about $1 being set to a prior match may need dealing with.
If ABSOLUTELY sure there are no double spaces or other nastiness, you could use index() in a for loop too. But it's ugly so someone else can do that...
--
$you = new YOU;
honk() if $you->love(perl)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: 30 Spaces- 1 question
by dchetlin (Friar) on Oct 09, 2000 at 07:01 UTC | |
by extremely (Priest) on Oct 09, 2000 at 10:07 UTC | |
by dchetlin (Friar) on Oct 09, 2000 at 11:07 UTC |