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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |