Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Hex to array conversion

by ChOas (Curate)
on Oct 08, 2007 at 13:49 UTC ( #643460=note: print w/replies, xml ) Need Help??


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)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://643460]
help
Chatterbox?
[Wcool]: hi
[Wcool]: I have this really weird behaviour of printing lines in a file
[Wcool]: Iam on linux and open a file, do some subs and then write it to a new file
[Wcool]: all fine
[Wcool]: but when I add something like this
[Wcool]: $lLine .= "$DECIMAL_FORMAT\n ";
[Wcool]: suddenly all the line are printed with ^M
[choroba]: sounds like MSWin text format
[Corion]: Wcool: You are reading a file with Windows newlines. Use s/\s+$// on each line

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-01-16 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (183 votes). Check out past polls.

    Notices?