Ok, I see that I'm doing more than I should, but so be it :)

use strict; use warnings; use vars qw( $WIDTH ); BEGIN { $WIDTH = 40; } sub detab { local *_ = @_ ? \($_[0]) : \$_; my $pos = 0; for (;;) { $pos = index($_, "\t", $pos); last if ($pos < 0); substr($_, $pos, 1) = ' 'x(int($pos/8+1)*8-$pos); } } sub flush_para { our $para; local *para = \($_[0]); our $indent; local *indent = \($_[1]); my $width = $_[2]; return unless (length($para)); my @lines; $width -= length($indent); $width = 20 if ($width < 20); while (length($para) > $width) { my $width2 = $width - 1; if ($para =~ s/^(.{0,$width2}\S)\s+//s) { # Break at space. push(@lines, $1); } else { # No space. $para =~ s/^(.{$width})//s; push(@lines, $1); } } push(@lines, $para); my $line_sep = "\n" . (' ' x length($indent)); print($indent . join($line_sep, @lines) . "\n"); $para = $indent = ''; } { print('='x$WIDTH, "\n"); my $fortune; local $/ = "\n".('='x67)."\n"; while (defined($fortune = <DATA>)) { chomp($fortune); my $para = ''; my $indent = ''; my $indent2 = ''; local $/ = "\n"; foreach (split(/\n/, $fortune)) { /^\s*$/ && do { flush_para($para, $indent, $WIDTH); $indent2 = ''; print("\n"); next; }; detab($_); /^((\s*)--\s*)(.*)/ && do { my @save = ($1, $2, $3); flush_para($para, $indent, $WIDTH); ($indent, $indent2, $para) = @save; next; }; # Good enough? /^((\s*)\S.{1,14}:\s*)(.*)/ && do { my @save = ($1, $2, $3); flush_para($para, $indent, $WIDTH); ($indent, $indent2, $para) = @save; next; }; /^(\s*)(.*)/; if (!length($para)) { ($indent, $indent2, $para) = ($1, $1, $2); next; } if (length($1) != length($indent) && length($1) != length($indent2)) { my @save = ($1, '', $2); flush_para($para, $indent, $WIDTH); ($indent, $indent2, $para) = @save; next; } $para .= ' ' . $_; } flush_para($para, $indent, $WIDTH); print('='x$WIDTH, "\n"); } } __DATA__ Bender: Stay away from our women. You got metal fever, baby, metal fe +ver! =================================================================== Kids, kids, kids. As far as Daddy's concerned, you're both potential murderers. -- Homer Simpson Who Shot Mr. Burns? (Part 2) =================================================================== Wh ... what's going on? Wh ... wha ... why am I on a Japanese box? -- Homer Simpson In Marge We Trust =================================================================== Who spread garbage all over Flanders's yard before I got a chance to? -- Homer Simpson Two Dozen and One Greyhounds =================================================================== THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? Bart Simpson on chalkboard in episode 2F16 =================================================================== "It was nice of you to let me reattach your arm." --Zoidber =================================================================== Calculon: An Oscar, you say? That would get me out of this festering rats' nest called television once and for all. =================================================================== Dasher, Dancer ... Prancer ... Nixon, Comet, Cupid ... Donna Dixon. -- Homer Simpson Simpsons Roasting on an Open Fire =================================================================== Homer: I suppose you want to probe me. Well, you might as well get it over with. Kang: Stop! We have reached the limits of what rectal probing can teach us. Treehouse of Horror VII Famous Original Ray's Superior Court =================================================================== It's okay, Marge. I've learned my lesson. A mountain of sugar is too much for one man. It's clear now why God portions it out in those tiny packets, and why he lives on a plantation in Hawaii. -- Homer Simpson Lisa's Rival =================================================================== Bender: "Tell the Donbot I'm quitting organized crime. From now on I'l +l stick to the regular kind." =================================================================== "Hurry up! I wanna see the moon." -Fry "Relax. It's open 'till nine." -Leela =================================================================== I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM Bart Simpson on chalkboard in episode AABF03 =================================================================== Calculon: I'm programmed to be very busy. =================================================================== "I don't care how many eyes a man has... as long as it's less than fi +ve." -Leela

Output:

======================================== Bender: Stay away from our women. You got metal fever, baby, metal fever! ======================================== Kids, kids, kids. As far as Daddy's concerned, you're both potential murderers. -- Homer Simpson Who Shot Mr. Burns? (Part 2) ======================================== Wh ... what's going on? Wh ... wha ... why am I on a Japanese box? -- Homer Simpson In Marge We Trust ======================================== Who spread garbage all over Flanders's yard before I got a chance to? -- Homer Simpson Two Dozen and One Greyhounds ======================================== THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? Bart Simpson on chalkboard in episode 2F16 ======================================== "It was nice of you to let me reattach your arm." --Zoidber ======================================== Calculon: An Oscar, you say? That would get me out of this festering rats' nest called television once and for all. ======================================== Dasher, Dancer ... Prancer ... Nixon, Comet, Cupid ... Donna Dixon. -- Homer Simpson Simpsons Roasting on an Open Fire ======================================== Homer: I suppose you want to probe me. Well, you might as well get it over with. Kang: Stop! We have reached the limits of what rectal probing can teach us. Treehouse of Horror VII Famous Original Ray's Superior Court ======================================== It's okay, Marge. I've learned my lesson. A mountain of sugar is too much for one man. It's clear now why God portions it out in those tiny packets, and why he lives on a plantation in Hawaii. -- Homer Simpson Lisa's Rival ======================================== Bender: "Tell the Donbot I'm quitting organized crime. From now on I'll stick to the regular kind." ======================================== "Hurry up! I wanna see the moon." -Fry "Relax. It's open 'till nine." -Leela ======================================== I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM Bart Simpson on chalkboard in episode AABF03 ======================================== Calculon: I'm programmed to be very busy. ======================================== "I don't care how many eyes a man has... as long as it's less than five." -Leela ========================================


In reply to Re^2: Removing Preformatted Word Wrapping by ikegami
in thread Removing Preformatted Word Wrapping by abitkin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.