use strict;
my $string = q~Suppose you run a Web site that includes a banner advertisement service. You contract with companies that want their ads displayed when poeple visit the pages on your site. Each time a visitor hits one of your pages, you serve an ad embedded in the page that is sent to the visitor's browser and assess the company a small fee. To represent this information, you maintain three tables. One table, company, has columns for company name, number, address, and telephone number. Another table, ad lists ad numbers, the number for the company that owns the ad, and the amount you charge per hit. The third table, hit, logs each ad hit by number and the date on which the ad was served.~;
my @words = split / /, $string;
my ($string_len, $new_string);
foreach (@words) {
my $space = 1;
$string_len += length($_);
if ($string_len >= 50) {
$new_string .= "$_
";
$string_len = 0;
$space = 0;
}
else {
$new_string .= $_;
$new_string .= ' ' if $space;
}
}
# output
Suppose you run a Web site that includes a banner advertisement
service. You contract with companies that want their ads displayed
when poeple visit the pages on your site. Each time a visitor
hits one of your pages, you serve an ad embedded in the page that
is sent to the visitor's browser and assess the company a small
fee. To represent this information, you maintain three tables.
One table, company, has columns for company name, number, address,
and telephone number. Another table, ad lists ad numbers, the
number for the company that owns the ad, and the amount you charge
per hit. The third table, hit, logs each ad hit by number and the
date on which the ad was served.