How to insert newline break into a long string 
Author Message
 How to insert newline break into a long string

Try adding this:
$content =~ s/(.{0,70}) /$1\n/g;
Adjust the 70 to however long you want the maximum length of a line to be,
provided
that there are no words longer than the length of the line.

Hi everyone,

     I have a very long string say 1000 characters called $content. If I
want send it to a friend like:

     print <<Mail;

     $content

     Mail

     It will be a very long line in the message. I want to insert newline
break into this long string at
     certain interval. Could you give me a hint ?

     Thanks,

     Sun

*** Posted from RemarQ - http://www.*-*-*.com/ - Discussions Start Here (tm) ***



Wed, 11 Jul 2001 03:00:00 GMT  
 How to insert newline break into a long string
Hi everyone,

I have a very long string say 1000 characters called $content. If I
want send it to a friend like:

print <<Mail;

$content

Mail

It will be a very long line in the message. I want to insert newline
break into this long string at certain interval. Could you give me
a hint ?

Thanks,

Sun



Thu, 12 Jul 2001 03:00:00 GMT  
 How to insert newline break into a long string
:Try adding this:
:$content =~ s/(.{0,70}) /$1\n/g;
:Adjust the 70 to however long you want the maximum length of a line to be,
:provided
:that there are no words longer than the length of the line.

We might want to also match the end of the line as well or we have the last
word on a line all by itself.

$content =~ s/(.{0,70})( |$)/$1\n/g;

There is also the issue of new lines, tabs, multiple spaces, etc..

I would look into the Text:Wrap or Text::Format modules.

HTH

AmD



Thu, 12 Jul 2001 03:00:00 GMT  
 How to insert newline break into a long string
:Hi everyone,
:I have a very long string say 1000 characters called $content. If I
:want send it to a friend like:
:print <<Mail;
:$content
:Mail
:It will be a very long line in the message. I want to insert newline
:break into this long string at certain interval. Could you give me
:a hint ?
:Thanks,
:Sun

I would look into the Text:Wrap or Text::Format modules.  e.g.:

#!/usr/local/bin/perl -w
use strict;
use Text::Wrap qw(wrap $columns);;
$columns = 70;

HTH

AmD



Thu, 12 Jul 2001 03:00:00 GMT  
 How to insert newline break into a long string

Quote:

> I want to insert newline
> break into this long string at certain interval. Could you give me
> a hint ?

use Text::Wrap;

--


    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."



Thu, 12 Jul 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. insert newlines in a long string

2. Insert newline into long string

3. Adding newlines to long strings

4. inserting a long string into access w/perl

5. search for string, then insert page break and header

6. How does one break a long string?

7. How does one break a long string?

8. mysql INSERT is broken by some charactors in the inserted record

9. How to insert a newline in Perl

10. Can't insert newline

11. $:, breaking a string after a string

12. Oraperl - Insert to a LONG type

 

 
Powered by phpBB® Forum Software