Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Split the line

Posted on 2000-05-02
6
Medium Priority
?
196 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

670 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