bdalzell has asked for the wisdom of the Perl Monks concerning the following question:
Is there an easy way to use Term::ANSIColor and printf together?
I want to output a formatted response to the terminal.
printf works fine for this project but the text is monochrome. I would like to be able to highlight some of the text within a line of formatted output
This works but is not elegant:
#!/usr/bin/perl use strict; use Term::ANSIColor qw(:constants); { local $Term::ANSIColor::AUTORESET = 1; print BOLD "Dog record\n"; my $nlabel = BLACK ."Name\:"; my $dogname = RED ."Silkenswift Blaze of Chaos"; my $pt = RED "DC "; my $ft = RED "LCM2 SORC GRC "; my $ot = RED "CD "; printf("%-14s %-41s %-20s \n","$nlabel $pt","$dogname","$ft $ot"); print BLACK ""; print BOLD "################################\n"; }
This is just an example. In the actual program variables are being used in the black text areas such as :
$thisdog{'name'}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Term::ANSIColor and printf - easy way to use them together
by tobyink (Canon) on Dec 03, 2012 at 21:38 UTC | |
by bdalzell (Sexton) on Dec 03, 2012 at 22:51 UTC | |
Re: Term::ANSIColor and printf - easy way to use them together
by johngg (Canon) on Dec 03, 2012 at 23:33 UTC |
Back to
Seekers of Perl Wisdom