[thelist] Perl - regular expressions

Keith cache at dowebs.com
Sat Dec 8 12:10:56 CST 2001


> I would like to split the paragraph into two parts (which ultimately
> will be displayed in two pages). The trick, however is that I do not
> wish to split in the middle of the word. I have a budget of, lets say
> 99 characters which will split the word "its" right in the middle. I
> would like page to essentially display up to character 99 minus first
> (or last) white space (I think that makes sense).

I'm with you,  Roee, I'd like to see the following reduced to a regex 
too....

$phrase = qq~Nine state attorneys general argued Friday that 
Microsoft must offer a stripped-down version of its Windows 
operating system and make its leading Office software compatible 
with competing operating systems~;

@phrase = split(/ /,$phrase);
foreach (@phrase){
  $word=length($_);
  if($count + $word <99){
    $first .= $_." ";
    $count=length($first);
  }else{
    push(@second,$_);
  }
}
chop($first);
$second = join(" ", at second);

keith




More information about the thelist mailing list