Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2017-12-17 13:03 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (464 votes). Check out past polls.