in reply to number of unique characters in a string

sub f { my $l = ''; my $u; for (sort split(//,$_[0])) { $u++,$l=$_ if ($_ ne $l); } return $u; }

Update: I posted this because it was faster than a hash based solution but OM_Zen's idea with rob_au's adjustment is even faster. I'd bench merlyn's Inline::C version, but I don't have Inline::C installed...

--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';