I have three integers:
($r, 开发者_C百科$g, $b) = (255, 128, 0);
I would like to print a string like:
"#FF8000"
using those variables.
How do I do this?
my $rgb = sprintf '#%02X%02X%02X', $r, $g, $b;
See sprintf and printf.
You could use pack
and unpack
, to get the hexadecimal string.
my $rgb = '#' . uc unpack 'H6', pack 'C3', $r, $g, $b;
精彩评论