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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Plaintext underlining tool
by chanio (Priest) on Jan 28, 2006 at 23:32 UTC | |
by martin (Friar) on Jan 29, 2006 at 07:46 UTC | |
by chanio (Priest) on Jan 31, 2006 at 00:27 UTC |