How do you print hexadecimal digits to a Perl string?

perl, string

Solution

my $rgb = sprintf '#%02X%02X%02X', $r, $g, $b;

See sprintf and printf.

Problem

I have three integers: ``` ($r, $g, $b) = (255, 128, 0); ``` I would like to print a string like: ``` "#FF8000" ``` using those variables. How do I do this?

Original source