How do I generate fixed width output in this statement ?
use Term::ANSIColor;
printf("%s",sprintf("[%8s]",colored(sprintf("\$%0.2f",$Price),'red')))
The %8s doesn't have any effect in this statement. Are there any color conscious format specifiers ?
Sure it does, it's just that the codes that change the color on your terminal also have a width, and so the string you pass to the first sprintf call is already more than 8 characters. Try it with
sprintf("[%18s]", ...
and you'll see an affect.
But the width of terminal codes is esoteric, so you're better off moving the color coding outside of the fixed-width formattng.
printf("[%s]", colored( sprintf("%8s", sprintf("\$%0.2f",$Price) ),'red') )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With