开发者

How do you print hexadecimal digits to a Perl string?

开发者 https://www.devze.com 2022-12-12 22:48 出处:网络
I have three integers: ($r, 开发者_C百科$g, $b) = (255, 128, 0); I would like to print a string like:

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

精彩评论

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