Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Term::ANSIColor and printf - easy way to use them together

by johngg (Abbot)
on Dec 03, 2012 at 23:33 UTC ( #1006964=note: print w/replies, xml ) Need Help??

in reply to Term::ANSIColor and printf - easy way to use them together

Another way using :constants is to either interpolate the BOLD, RED, RESET, whatever into the string using the @{ [ ... ] } construct or make them separate items in the printf with their own %s format specifier. Remember that the constants return ANSI control character sequences that will "take" some of the format width in the first method. That doesn't matter on the first line but would become trickier for the column items of the second line.

use strict; use warnings; use Term::ANSIColor qw{ :constants }; printf qq{%s\nName:%s%-9s%-41s%s%-14s%s%-6s%s\n}, qq{@{ [ BOLD ] }Dog record@{ [ RESET ] }}, RED, q{DC}, q{Silkenswift Blaze of Chaos}, GREEN, q{LCM2 SORC GRC}, BLUE, q{CD}, RESET;

I hope this is helpful.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006964]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-05-23 23:45 GMT
Find Nodes?
    Voting Booth?