in reply to next power of two


I don't know if it is the original that you refer to but here is a obfu/joke node from 2002 where I use this technique: Power Twool.
sub powa2 { ; local %_ = @_ ; keys %_ = pop ; $_ = %_ ; split '\/' ; pop }

--
John.

Replies are listed 'Best First'.
Re^2: next power of two
by shmem (Chancellor) on Nov 26, 2007 at 18:04 UTC
    Well, I have been the poster to fwp... and I looked up your node after I posted (but I definitely knew there must be something around like that in the monastery). Here is the exciting answer from Uri:
    >>>>> "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}