in reply to Re: next power of two
in thread next power of two
>>>>> "s" == shmem <gm@cruft.de> writes: s> You forgot an obscure corner of hashes: hashes in scalar context. s> Here's a a use - calculate the next power of 2 of a given number: s> sub next_power_of_two { s> my %s; s> @s{1..shift} = (); s> %s =~ '/'; s> return $'; s> } s> ;-) GACK!!! and that assume knowledge of the internals of hashes. not a good thing to teach! :) uri
but your version is much more elegant, except perhaps the %s =~ '/' thingy ;-D
update: and I posted it only because the discussion went into discussing the pros and cons of dispatch tables, oo, inheritance etc pp... in short, to introduce some fun again ;-)
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|