http://qs321.pair.com?node_id=643460


in reply to Hex to array conversion

Works too:
my @rgb = map {hex($_) } unpack 'xa2a2a2', "#FF00FF"; print "(",join(',',@rgb),")\n";

GreetZ!,
    ChOas

print "profeth still\n" if /bird|devil/;

Replies are listed 'Best First'.
Re^2: Hex to array conversion
by bart (Canon) on Oct 08, 2007 at 14:32 UTC
    While we're busy doing silly pack/unpack strings:
    $str = '#FE00FD'; $str =~ tr/0-9a-fA-F//cd; # remove non-hex characters my @rgb = unpack 'C*', pack 'H*', $str; # pack hex as 3 bytes, unpack + into list of 3 character codes $" = ","; $\ = "\n"; print "(@rgb)";
    Result:
    (254,0,253)