in reply to Sorting, recursion, and tail-call optimizations
Update: Except this doesn't work (at least, it doesn't sort in any way that I consider sensible). Not sure what I did wrong. And oddly enough, when I translated it into what I thought was an equivalent for-loop, I got a different arrangement. I think it's what you want.sub my_sort { SUB_BODY: { my $i = $_[0] || 0; if ( defined $a->[$i] && defined $b->[$i] ) { if ( my $result = $a->[$i] <=> $b->[$i] ) { return $result; } ++$_[0]; redo SUB_BODY; } return defined $a->[$i] ? 1 : -1; } }
So I guess I'm just having a high-Bozo-quotient day. But maybe you can make use of the idea.sub my_sort { my $i; for ($i = 0; defined $a->[$i] && defined $b->[$i]; ++$i) { if ( my $result = $a->[$i] <=> $b->[$i] ) { return $result; } } return defined $a->[$i] ? 1 : -1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting, recursion, and tail-call optimizations (why? $i)
by tye (Sage) on Jan 07, 2006 at 00:47 UTC | |
by Roy Johnson (Monsignor) on Jan 09, 2006 at 14:17 UTC | |
by tye (Sage) on Jan 09, 2006 at 14:32 UTC | |
by Roy Johnson (Monsignor) on Jan 09, 2006 at 16:32 UTC | |
|
Re^2: Sorting, recursion, and tail-call optimizations
by Limbic~Region (Chancellor) on Jan 06, 2006 at 19:51 UTC |