Solved

Split the line

Posted on 2000-05-02
6
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Author Comment

by:sstouk
ID: 2770196
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
ID: 2770209
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
ID: 2770232
I need it for the site that I developed:
www.members.home.net/sstouk
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:maneshr
ID: 2770283
Aha!! MCSE braindumps are my favourite too!!
0
 
LVL 6

Author Comment

by:sstouk
ID: 2770310
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
ID: 2770595
most welcome, sir :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…

752 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