in reply to underline variable width column headings

It doesn’t help me for what I want to do, because I am using Perl, version 5.005_01 built for powerpc-machten (BSD 4.4) and I cant use modules.
Yes you can.
# Term::ANSIColor -- Color screen output using ANSI escape sequences. # $Id: ANSIColor.pm 58 2006-07-12 22:30:55Z eagle $ # # Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006 # by Russ Allbery <rra@stanford.edu> and Zenin # # This program is free software; you may redistribute it and/or modify + it # under the same terms as Perl itself. # # Ah, September, when the sysadmins turn colors and fall off the trees +.... # -- Dave Van Domelen ###################################################################### +######## # Modules and declarations ###################################################################### +######## package Term::ANSIColor; require 5.001; use strict; use vars qw($AUTOLOAD $AUTORESET $EACHLINE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION %attributes %attributes_r); use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(color colored); @EXPORT_OK = qw(uncolor); %EXPORT_TAGS = (constants => [qw(CLEAR RESET BOLD DARK UNDERLINE UNDER +SCORE BLINK REVERSE CONCEALED BLACK RED GRE +EN YELLOW BLUE MAGENTA CYAN WHITE ON_BLA +CK ON_RED ON_GREEN ON_YELLOW ON_BLUE ON_ +MAGENTA ON_CYAN ON_WHITE)]); Exporter::export_ok_tags ('constants'); $VERSION = '1.11'; ###################################################################### +######## # Internal data structures ###################################################################### +######## %attributes = ('clear' => 0, 'reset' => 0, 'bold' => 1, 'dark' => 2, 'underline' => 4, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'concealed' => 8, 'black' => 30, 'on_black' => 40, 'red' => 31, 'on_red' => 41, 'green' => 32, 'on_green' => 42, 'yellow' => 33, 'on_yellow' => 43, 'blue' => 34, 'on_blue' => 44, 'magenta' => 35, 'on_magenta' => 45, 'cyan' => 36, 'on_cyan' => 46, 'white' => 37, 'on_white' => 47); # Reverse lookup. Alphabetically first name for a sequence is preferr +ed. for (reverse sort keys %attributes) { $attributes_r{$attributes{$_}} = $_; } ###################################################################### +######## # Implementation (constant form) ###################################################################### +######## # Time to have fun! We now want to define the constant subs, which ar +e named # the same as the attributes above but in all caps. Each constant sub + needs # to act differently depending on whether $AUTORESET is set. Without # autoreset: # # BLUE "text\n" ==> "\e[34mtext\n" # # If $AUTORESET is set, we should instead get: # # BLUE "text\n" ==> "\e[34mtext\n\e[0m" # # The sub also needs to handle the case where it has no arguments corr +ectly. # Maintaining all of this as separate subs would be a major nightmare, + as well # as duplicate the %attributes hash, so instead we define an AUTOLOAD +sub to # define the constant subs on demand. To do that, we check the name o +f the # called sub against the list of attributes, and if it's an all-caps v +ersion # of one of them, we define the sub on the fly and then run it. # # If the environment variable ANSI_COLORS_DISABLED is set, turn all of + the # generated subs into pass-through functions that don't add any escape # sequences. This is to make it easier to write scripts that also wor +k on # systems without any ANSI support, like Windows consoles. sub AUTOLOAD { my $enable_colors = !defined $ENV{ANSI_COLORS_DISABLED}; my $sub; ($sub = $AUTOLOAD) =~ s/^.*:://; my $attr = $attributes{lc $sub}; if ($sub =~ /^[A-Z_]+$/ && defined $attr) { $attr = $enable_colors ? "\e[" . $attr . 'm' : ''; eval qq { sub $AUTOLOAD { if (\$AUTORESET && \@_) { '$attr' . "\@_" . "\e[0m"; } else { ('$attr' . "\@_"); } } }; goto &$AUTOLOAD; } else { require Carp; Carp::croak ("undefined subroutine &$AUTOLOAD called"); } } ###################################################################### +######## # Implementation (attribute string form) ###################################################################### +######## # Return the escape code for a given set of color attributes. sub color { return '' if defined $ENV{ANSI_COLORS_DISABLED}; my @codes = map { split } @_; my $attribute = ''; foreach (@codes) { $_ = lc $_; unless (defined $attributes{$_}) { require Carp; Carp::croak ("Invalid attribute name $_"); } $attribute .= $attributes{$_} . ';'; } chop $attribute; ($attribute ne '') ? "\e[${attribute}m" : undef; } # Return a list of named color attributes for a given set of escape co +des. # Escape sequences can be given with or without enclosing "\e[" and "m +". The # empty escape sequence '' or "\e[m" gives an empty list of attrs. sub uncolor { my (@nums, @result); for (@_) { my $escape = $_; $escape =~ s/^\e\[//; $escape =~ s/m$//; unless ($escape =~ /^((?:\d+;)*\d*)$/) { require Carp; Carp::croak ("Bad escape sequence $_"); } push (@nums, split (/;/, $1)); } for (@nums) { $_ += 0; # Strip leading zeroes my $name = $attributes_r{$_}; if (!defined $name) { require Carp; Carp::croak ("No name for escape sequence $_" ); } push (@result, $name); } @result; } # Given a string and a set of attributes, returns the string surrounde +d by # escape codes to set those attributes and then clear them at the end +of the # string. The attributes can be given either as an array ref as the f +irst # argument or as a list as the second and subsequent arguments. If $E +ACHLINE # is set, insert a reset before each occurrence of the string $EACHLIN +E and # the starting attribute code after the string $EACHLINE, so that no a +ttribute # crosses line delimiters (this is often desirable if the output is to + be # piped to a pager or some other program). sub colored { my ($string, @codes); if (ref $_[0]) { @codes = @{+shift}; $string = join ('', @_); } else { $string = shift; @codes = @_; } return $string if defined $ENV{ANSI_COLORS_DISABLED}; if (defined $EACHLINE) { my $attr = color (@codes); join '', map { $_ ne $EACHLINE ? $attr . $_ . "\e[0m" : $_ } grep { length ($_) > 0 } split (/(\Q$EACHLINE\E)/, $string); } else { color (@codes) . $string . "\e[0m"; } } package main; die "YOUR CODE HERE";
If that doesn't help you, you need to learn " ANSI escape sequences".

Replies are listed 'Best First'.
Re^2: underline variable width column headings
by wlegrand (Initiate) on Oct 30, 2006 at 19:22 UTC
    Anonymous Monk, thank you for your reply. Perhaps I should have said I couldn’t use modules because I don’t know how to download and compile anything in MachTen. I had previously tried to upgrade to Perl 5.8 but couldn’t. I’m just a user. Other than the program I have which I tried to enhance, I don’t program or do any kind of system administration. I am seventy two and retired. I have bought several Perl books and tried to learn Perl programing, but because I don’t program for a living, or get enough Perl practice, I forget what I learned after a while. I no longer have the retention I used to have. I will try again to see if I can install the latest stable Perl in MachTen. One day, I will buy a new Mac, and hopefully I’ll have what I need. I regret any inconvenience I have caused you or the other members. I didn’t know who else to ask.
      I was successful in building perl-5.6.2 on Machten 4.1.4. That is the highest version that is supported. That’s all it took for me to be able to underline because it contains the module Term::ANSIColor. Now all I have to do is to get it to work on my file. Thanks for your help.