in reply to Re: Re (tilly) 1: (Golf) Building a Better Binary Tree
in thread (Golf) Building a Better Binary Tree

I haven't tested under Perl 5.6, but under 5.005 your code does not work.

Remember that the comparison function specified depends on the arguments passed to it, and not on $a and $b. Therefore the comparison function is not a valid sort sub and you need to do that transform.

Try this to see what I mean.

print Dumper h(sub {$_[0] <=> $_[1]}, 1..6, -3);
With your code that fails. (BTW your other solution also seems to have used this incorrect optimization.)