Solved

Split the line

Posted on 2000-05-02
6
145 Views
Last Modified: 2010-03-05
Could anyone give an example of a good subroutine for splitting a long string (line) into predefined length several lines without breaking the words inside the original line of text?

Say the input would be $longline with the length of 1000 chars
the output could be an array of @shortlines with each element is a line of no more than 60 chars and there should be no words broken.

Thank You.
0
Comment
Question by:sstouk
  • 3
  • 3
6 Comments
 
LVL 6

Author Comment

by:sstouk
Comment Utility
I need it for the site that I developed:
www.members.home.net/sstouk
0
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
Comment Utility
try this...

Text::Wrap is line wrapping module used to form simple paragraphs.

wrap() is a very simple paragraph formatter.  It  formats a single paragraph at a time by breaking lines at word boundries.

you can change the column variable to the value to want to break at.


========my wrap.pl
#!/usr/local/bin/perl

use Text::Wrap;
$columns = 60;
use Text::Wrap qw(wrap $columns);

$text="Monitor your portfolio, or select a watch list of securities and get per
formance charts, research and Dow Jones News related to your holdings. Go to: A
ccount Summary, Portfolio Summary, Positions, Activities, Account Download, Wat
ch List, Trade.";
     
print wrap("","", $text);
0
 
LVL 6

Author Comment

by:sstouk
Comment Utility
I need it for the site that I developed:
www.members.home.net/sstouk
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 16

Expert Comment

by:maneshr
Comment Utility
Aha!! MCSE braindumps are my favourite too!!
0
 
LVL 6

Author Comment

by:sstouk
Comment Utility
This function does exactly what I need. Even more. I can assign the second parameter in the Wrap function as the separator "<BR>" and it can be nicely wrapped for displaying on the Web.

Thanks alot!
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
most welcome, sir :)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now