Here is a small tool I use to underline plaintext. It has a little bit more logic than the vi idiom yyp:s/./-/g built into it in that it can generate underlining patterns of more than one character (like o=o=o=o) and it copys indentation and bigspace (i.e. whitespace containing tabs) as-is from the original text.

To minimize typing overhead I install it under 5 different names (using links) and let it use its name as a parameter. The names aul, bul, cul and dul give me four standard line types, while pul takes an arbitrary line pattern as its first argument.

#!/usr/bin/perl # aul, bul, cul, dul, pul - plaintext underline helpers # [abcd]ul use some fixed underline character, # pul uses its first argument as pattern use strict; use warnings; use integer; use File::Basename qw(basename); $0 = basename($0); my $pat = {qw(a - b = c ~ d ^)}->{substr($0, 0, 1)} || shift; die "usage: $0 pattern [file]...\n" if !defined($pat) || '' eq $pat; my $len = length($pat); while (<>) { print; s/\S/x/g; # underline non-whitespace 1 while s/x (?= *x)/xx/; # and inner blanks if (1 == $len) { # finally apply texture s/x/$pat/g; } else { s{(x+)}{substr( $pat x (length($1)/$len+1), 0, length($1) )}ge; } print; }

In reply to Plaintext underlining tool by martin

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.