is there a way to get with printf
colored output?
#!/usr/bin/perl
use warnings;
use strict;
use Term::ANSIColor;
printf "%4.4s\n", colored( '0123456789', 'magenta' );
Output: (only newline)
If you want to use colors in print do the folowing: use Term::ANSIColor qw(:constants); And then use the specific colors names. For example: If you want to print text in green bold color, use: print GREEN BOLD "Passed", RESET; .
I assume you want something like the following:
#!/usr/bin/perl
use warnings;
use strict;
use Term::ANSIColor;
print colored( sprintf("%4.4s", '0123456789'), 'magenta' ), "\n";
You need to change your code like the following
printf "%s\n", colored( '0123456789', 'magenta' );
Because we can't get the first 4 character in the string. If you give the string value to the printf function it will print the value up to null character. We can't get the first 4 characters.
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