Converting RGB to hex just involves understanding the decimal representation of RGB. See below for a small perl procedure.
sub RGB2Hex
{
my $r = shift;
my $g = shift;
my $b = shift;
my $dec = 0;
$dec += 256*256*$r;
$dec += 256*$g;
$dec += $b;
return sprintf(“%.6x”, $dec);
}
#!/usr/bin/perl
$foo = 10;
$hexval = sprintf("%x", $foo);
$decval = hex($hexval);
print "n$foo in hex is $hexval and in dec is $decvaln";
# end
Cut and paste the above code into a new file, save it as hexdec.pl or dechex.pl or whatever and ensure that you have execute permissions. The script creates a variable, $foo with a value of your choice, (in this case 10). It will then print out it's value in hexadecimal and in decimal.
Christo
follow me on twitter to catch all my tech updates: http://www.twitter.com/planet_guru
Relevant pages:
- Perl Foreach Key Hash
A short tutorial (with free source code) that shows how to sort a Perl hash by the hash key. We also have a companion article on how to sort a Perl hash by the hash value.
- Perl Whitespace Remove
- The Superlative Horse
- Perl Appending Arrays
- Kirby Morgan Superlite 27




