Funny. I've been using this little script, which I named simply "wrap", for ... uh ... well, years now that I think about it. It's a wrapper around Text::Wrap's wrap() function. If I recall, I wrote it because I wanted to be able to use the "initial_tab" and "subsequent_tabs" feature of Text::Wrap. It only outputs to stdout. I generally call it from vi and haven't needed to write the output directly to a file, but if I ever do there's always redirection.

#!/usr/bin/perl -w use strict; # Description: Text wrapper kind of like fmt. use Getopt::Std; use Text::Wrap; my $USAGE =<<EOU; $0: [-c columns] [-i initial_tab] [-s subsequent_tabs] [-h] file ... -c Set column width for wrapping. -i Set initial 'tab' string for first paragraph line. -s Set a 'tab' string for subsequent paragraph lines. EOU local $/ = ''; my %O; getopts("c:i:s:h", \%O); if ($O{'h'}) { print $USAGE; exit; } $Text::Wrap::columns = $O{'c'} || 80; my $inittab = exists $O{'i'} ? eval("qq($O{'i'})") : ''; my $subtabs = exists $O{'s'} ? eval("qq($O{'s'})") : ''; while (<>) { s/\n/ /g; $_ .= "\n\n"; print Text::Wrap::wrap($inittab, $subtabs, $_); }

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Small wrapper for Text::Wrap's fill() by sauoq
in thread Small wrapper for Text::Wrap's fill() by broquaint

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.