Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert rgb to html hex code 1

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi there,
I am trying to create a function that converts rgb values to html hex color code.

The function prints the color codes correctly to the screen, but what I need to do is to have this function return the string instead of printing it.

Code:
sub rgbToHex {
    $red=$_[0];
    $green=$_[1];
    $blue=$_[2];
    printf (" #%2.2X%2.2X%2.2X\n",$red,$green,$blue);
    return (" #%2.2X%2.2X%2.2X\n",$red,$green,$blue)
}

Currently, it doesn't return the correct html value (but prints the value correctly to screen).
I am guessing that's something to do with the printf function. Is there anyway I can have this hex code returned as a string variable that having it print to the screen instead?
 
Code:
sub rgbToHex {
    $red=$_[0];
    $green=$_[1];
    $blue=$_[2];
    [b]$string[/b]=[COLOR=red]s[/color]printf (" #%2.2X%2.2X%2.2X\n",$red,$green,$blue);
    return ([b]$string[/b]);
}

HTH

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks Paul! that did just the trick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top