On Tue, 2002-07-16 at 15:14, Anthony E. wrote: > hello, > > i have a bunch of text in a scalar $text > How would I keep the word count to a maximum, and just > dump the rest.. ie - I only want the paragraph to > contain 500 words, and trash the rest. > > Thanks, > Anthony
ASSUMPTIONS: 1. a word is delimited by one or more whitespace characters 2. the output words can be space delimited 3. the are no non-breaking spaces ANSWER: <code> #!/usr/bin/perl -w use strict; my $text = "this is a test of trimming down to 5 words"; my $teaser = join ' ', (split /\s+/, $text)[0..4]; print "$teaser\n"; __END__ </code> -- Today is Boomtime the 51st day of Confusion in the YOLD 3168 Frink! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]