This is a very simple snippet, but one I was looking around for last night. Since I was never really a C programmer, it takes me to much time to figure out the printf format. Anyway, the data I have for RGB color info was 3 decimal numbers and I needed to have them converted into the HTML hex color code to use as background for table cells.
$color = &RGBDecToHex(0, 102, 153); sub RGBDecToHex { my ($red, $green, $blue) = @_; return sprintf("#%02lx%02lx%02lx", $red, $green, $blue); }

Replies are listed 'Best First'.
Browser safe colors :)
by AltBlue (Chaplain) on Sep 13, 2000 at 10:52 UTC
    heh. seeing your snippet remembered of some neat stuff i did sometime ago to check up a nice code (Permutations and combinations) written by merlyn
    here is a quick list of the so called 'browser safe colors':
    #!/usr/bin/perl -w use strict; my @clrs = ('00','33','66','99','CC','FF'); my $sw; print '#',join('',@$_),(++$sw%6?$":$/) for permute(\@clrs,\@clrs,\@clr +s); sub permute { my $last = pop @_; return map [$_], @$last if(!@_); return map { my $left = $_; map [@$left, $_], @$last } permute(@_); }

    --
    AltBlue.

      Nice Code.. but any idea how you would generate these colors so that like colors are together?

        Hm, define “like colors” and “together” ;-)