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

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.

Cheers,

JohnGG


Comment on Re: Term::ANSIColor and printf - easy way to use them together
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-12-28 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls