Solved

Split the line

Posted on 2000-05-02
6
179 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
Industry Leaders: 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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 have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

749 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