开发者

How do you print hexadecimal digits to a Perl string?

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜