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
Solved

Split the line

Posted on 2000-05-02
6
172 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
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
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.

 
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

Suggested Solutions

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…
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…

828 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