Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   splitting lines (http://www.velocityreviews.com/forums/t882640-splitting-lines.html)

Bob Smith 09-22-2003 04:41 PM

splitting lines
 
hi
how to split text into lines?
I have in a db whitespace delimited words forming chapters in one field,
and I want to nicely put it on the page with max 30 or so characters per
paragraph, after that line breaks should occur,
but I can't figure out the regexp for doing it,
any help much appreciated. Thank you
/G


Bigus 09-22-2003 05:20 PM

Re: splitting lines
 

"Bob Smith" <bobsmith@jippii.fi> wrote in message
news:3F6F2625.B949AE9@jippii.fi...
> hi
> how to split text into lines?
> I have in a db whitespace delimited words forming chapters in one field,
> and I want to nicely put it on the page with max 30 or so characters per
> paragraph, after that line breaks should occur,


I take it you mean 30 characters per line rather than paragraph?

If so, try something like this:

@lines = $dbtext =~ /(.{30}\S*)/g;
foreach(@lines)
{
$_ =~ s/^\s+//;
print "$_\n";
}

Bigus



D Borland 09-22-2003 06:03 PM

Re: splitting lines
 

"Bigus" <bigus_34@yahoo.co.uk> wrote in message
news:QbGbb.1792$jJ3.27457@newsfep4-glfd.server.ntli.net...
>
> "Bob Smith" <bobsmith@jippii.fi> wrote in message
> news:3F6F2625.B949AE9@jippii.fi...
> > hi
> > how to split text into lines?
> > I have in a db whitespace delimited words forming chapters in one field,
> > and I want to nicely put it on the page with max 30 or so characters per
> > paragraph, after that line breaks should occur,

>
> I take it you mean 30 characters per line rather than paragraph?
>
> If so, try something like this:
>
> @lines = $dbtext =~ /(.{30}\S*)/g;
> foreach(@lines)
> {
> $_ =~ s/^\s+//;


can't that be typed just as s/^\s+//; not $_ =~ s^\s+//;

> print "$_\n";
> }
>
> Bigus
>
>




Trent Curry 09-22-2003 07:03 PM

Re: splitting lines
 
D Borland wrote:
> "Bigus" <bigus_34@yahoo.co.uk> wrote in message
> news:QbGbb.1792$jJ3.27457@newsfep4-glfd.server.ntli.net...
>>
>> "Bob Smith" <bobsmith@jippii.fi> wrote in message
>> news:3F6F2625.B949AE9@jippii.fi...
>>> hi
>>> how to split text into lines?
>>> I have in a db whitespace delimited words forming chapters in one
>>> field, and I want to nicely put it on the page with max 30 or so
>>> characters per paragraph, after that line breaks should occur,

>>
>> I take it you mean 30 characters per line rather than paragraph?
>>
>> If so, try something like this:
>>
>> @lines = $dbtext =~ /(.{30}\S*)/g;
>> foreach(@lines)
>> {
>> $_ =~ s/^\s+//;

>
> can't that be typed just as s/^\s+//; not $_ =~ s^\s+//;


Yes it can, since s/ (a substitution op) with no lhs implies using $_;

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'



Eric Bohlman 09-22-2003 09:03 PM

Re: splitting lines
 
Bob Smith <bobsmith@jippii.fi> wrote in news:3F6F2625.B949AE9@jippii.fi:

> hi
> how to split text into lines?
> I have in a db whitespace delimited words forming chapters in one field,
> and I want to nicely put it on the page with max 30 or so characters per
> paragraph, after that line breaks should occur,
> but I can't figure out the regexp for doing it,


You're better off using Text::Format, or Text::Autoformat, or a related
module for this rather than trying to create a regexp. The authors of
those modules have already dealt with a number of "gotchas" that occur in
text formatting.

Bigus 09-23-2003 02:35 PM

Re: splitting lines
 
"Trent Curry" <tcurrey@no.no.no.i.said.no> wrote in message
news:bknh7a$rtb$1@news.astound.net...
> D Borland wrote:
> > "Bigus" <bigus_34@yahoo.co.uk> wrote in message
> > news:QbGbb.1792$jJ3.27457@newsfep4-glfd.server.ntli.net...
> >>
> >> "Bob Smith" <bobsmith@jippii.fi> wrote in message
> >> news:3F6F2625.B949AE9@jippii.fi...
> >>> hi
> >>> how to split text into lines?
> >>> I have in a db whitespace delimited words forming chapters in one
> >>> field, and I want to nicely put it on the page with max 30 or so
> >>> characters per paragraph, after that line breaks should occur,
> >>
> >> I take it you mean 30 characters per line rather than paragraph?
> >>
> >> If so, try something like this:
> >>
> >> @lines = $dbtext =~ /(.{30}\S*)/g;
> >> foreach(@lines)
> >> {
> >> $_ =~ s/^\s+//;

> >
> > can't that be typed just as s/^\s+//; not $_ =~ s^\s+//;

>
> Yes it can, since s/ (a substitution op) with no lhs implies using $_;


That's interesting.. I never knew that!

Bigus



Mala Ananthamurthy 09-23-2003 07:12 PM

Re: splitting lines
 
Bob Smith <bobsmith@jippii.fi> wrote in message news:<3F6F2625.B949AE9@jippii.fi>...
> hi
> how to split text into lines?
> I have in a db whitespace delimited words forming chapters in one field,
> and I want to nicely put it on the page with max 30 or so characters per
> paragraph, after that line breaks should occur,
> but I can't figure out the regexp for doing it,
> any help much appreciated. Thank you
> /G


$outputline =~ s/(.{1,30})/$1\n/gs;

print "$outputline";

Mala Ananthamurthy 09-23-2003 07:56 PM

Re: splitting lines
 
Bob Smith <bobsmith@jippii.fi> wrote in message news:<3F6F2625.B949AE9@jippii.fi>...
> hi
> how to split text into lines?
> I have in a db whitespace delimited words forming chapters in one field,
> and I want to nicely put it on the page with max 30 or so characters per
> paragraph, after that line breaks should occur,
> but I can't figure out the regexp for doing it,
> any help much appreciated. Thank you
> /G


#This one looks for space character
$outputline =~ s/(.{1,30})\s+/$1\n/gs;

print "$outputline";


All times are GMT. The time now is 05:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.