[Wellington-pm] Pack/unpack - nagging guilt
michael@diaspora.gen.nz
michael at diaspora.gen.nz
Wed Jun 22 04:46:16 PDT 2005
Grant McLean writes:
>Anyone got any other imaginative solutions? With or without unpack.
Basically, you're looking to group 4 hex digits together, and add them
up, multiplying the existing total by 16 with each new digit:
$_ = '#FFFFCCCC3333';
my @rgb;
my $c;
for (/\w/g) {
push @rgb, eval "0x$_";
$c++ % 4 and ($rgb[-2] *= 16) += pop @rgb;
}
I believe that's about as perverse as I can make things. Fits with the
tone of the list, I suppose :).
If anyone can explain why the following gives the error message
"Modification of non-creatable array value attempted, subscript -2",
I'd be interested:
($c+=push @rgb, eval "0x$_") % 4 and ($rgb[-2] *= 16) += pop @rgb for /\w/g;
I'm quite confident there's a more perverse, golfier regexp based solution
out there waiting to be discovered -- anyone want to take a shot?
-- michael.
More information about the Wellington-pm
mailing list