[thelist] Perl - regular expressions

Mal Wins malwinsc at yahoo.com
Sat Dec 8 12:03:30 CST 2001


--- Roee Rubin <webdesign1 at irubin.com> wrote:
> Hello,
> 
> This question involves splitting up a paragraph,
> take for example the
> following paragraph:

This is pretty easy once you get the basic idea down.
Have to assume you already have your paragraph in a
variable. Say $para, split $para based on a space and
push that into an array. Then go through each word,
getting the word count by spliting on the null
char.($#char +1 will return the length of the array,
+1 since it starts at 0) Should add one to the count
for each word to account for spaces but for what you
outlined it isn't necessary. Tricky part here is that
you have to assign your limit ($break) and then check
before you operate on that word. If its over the
limit, it goes to the next step. 
So it looks like this....

@words = split(/ /, $para);
$break = "99";
foreach $word (@words) {
	@chars = split(//, $word);
	$wordcount = $#chars + 1;
	$textcnt = $wordcount + $cnt;
	if ($textcnt >= $break)
		{ &addwordPageOne($word);}
		else { &addwordPageTwo($word); }
			}


HTH

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com




More information about the thelist mailing list